// Merge two sets of FileInfo's, by path. // Input vectors must be sorted. Output will be sorted. // Where a path is present in both inputs, directories are selected // in preference to non-directories; otherwise, the FileInfo from the // first vector is selected in preference to the second vector. static void file_union_merge( std::vector<FileInfo>::const_iterator a, std::vector<FileInfo>::const_iterator aend, std::vector<FileInfo>::const_iterator b, std::vector<FileInfo>::const_iterator bend, std::vector<FileInfo> &output) { while ((a != aend) && (b != bend)) { int order = a->GetPath().compare(b->GetPath()); int which = order; if (which == 0) { if (b->IsDir() && !a->IsDir()) { which = 1; } else { which = -1; } } if (which < 0) { output.push_back(*a++); if (order == 0) ++b; } else { output.push_back(*b++); if (order == 0) ++a; } } if (a != aend) { std::copy(a, aend, std::back_inserter(output)); } if (b != bend) { std::copy(b, bend, std::back_inserter(output)); } }