It is a kind of associative container where each element must be unique. The element’s value cannot be modified once it has been added to the set, although it is possible to remove and add the modified value from that element.
Example:
std::multiset
It is similar to std::set, but stores duplicate elements, eg:
With std::set if we double the numbers like this:
The output will be: 8 11 13 17 , that is, it will not be duplicated.
Actually that was possible using a temporary variable, so it had a memory copy of the value. Already with std::move the exchange is really done without copying, example based on that:
This performs better than that example.
That’s all for today, small daily doses that will always keep us in tune with C++!