我发现执行简单的set操作的the C++ STL method相当笨拙。例如,要找到两组之间的差异:
std::set<int> newUserIds;
set_difference(currentUserIds.begin(), currentUserIds.end(), mPreviousUserIds.begin(), mPreviousUserIds.end(), std::inserter(newUserIds, newUserIds.end()));
std::set<int> missingUserIds;
set_difference(mPreviousUserIds.begin(), mPreviousUserIds.end(), currentUserIds.begin(), currentUserIds.end(), std::inserter(missingUserIds, missingUserIds.end()));
mPreviousUserIds = currentUserIds;
boost是否提供了一组可供选择的类,这些类会将上述示例简化为:
set_type<int> newUserIds = currentUserIds.difference(mPreviousUserIds);
set_type<int> missingUserIds = mPreviousUserIds.difference(currentUserIds);
(类似于Qt中的QSet,它以这种方式覆盖
operator-
。) 最佳答案
参见Boost Range Set algorithms。他们仍然希望有一个输出迭代器。
关于c++ - boost是否具有比STL更简单的set操作数据类型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15090209/