I'd like to extract the differences between two sets. This question provides an adequate answer when I need the result in another container as well.
The following code demonstrates what I'd like to do:
std::set<std::string> s1, s2, difference;
std::string difference_string = "";
std::set_difference(
s1.begin(), s1.end(), s2.begin(), s2.end(),
std::inserter(difference, difference.end()));
for (const std::string& s: difference) {
difference_string += s + ",";
}
if (0 < duplicateInPorts.size()) {
difference_string.pop_back(); //remove last comma
}
except I find it inconvenient to create a local variable, when in essence I'd like to have a string only about the contents; Which I could easily compile with a lambda.
Is there a convenience function in std
which would enable me to do that?
What I had in mind has similar syntay as std::transform
.