+template<class SET>
+void partition_sets( const SET ¤t, const SET &old,
+ SET &added, SET &common, SET &deleted ) {
+ FileDataNameCmp cmp;
+
+ set_difference( current.begin(), current.end(),
+ old.begin(), old.end(),
+ inserter( added, added.begin() ),
+ cmp );
+
+ set_difference( old.begin(), old.end(),
+ current.begin(), current.end(),
+ inserter( deleted, deleted.begin() ),
+ cmp );
+
+ set_union( current.begin(), current.end(),
+ old.begin(), old.end(),
+ inserter( common, common.begin() ),
+ cmp );
+}
+
+int main() {
+ // Parse the list of current files on stdin
+ file_set current;
+ populate_set( cin, current );
+
+ file_set backed_up;
+ ifstream db( "test.db" );
+ populate_set( db, backed_up);
+
+ // Now divide the two sets into three sets (added, deleted and common )
+ file_set added, deleted, common;
+ partition_sets( current, backed_up, added, common, deleted );
+
+ { // This little block will copy the last_backup_date from the second set to the first
+ FileDataNameCmp cmp;
+
+ file_set updated_mirror;
+ set_union( current.begin(), current.end(),
+ backed_up.begin(), backed_up.end(),
+ inserter( updated_mirror, updated_mirror.begin() ),
+ cmp );
+
+ // TODO Now we need to copy the last_backup_date from
+ file_set::iterator i = common.begin(), j = updated_mirror.begin();
+ for( ; i != common.end(); ++i, ++j ) {
+ (*i)->setLastBackupDate( (*j)->getLastBackupDate() );