Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++ does std::multiset keep a stable sorting order?

Tags:

c++

stl

Suppose I have two items, a and b, that compare the same. So a < b is false, and b < a is false. If these items are inserted into a std::multiset (or std::multimap) as keys, do I have any guarantees of their final sorted order?

I've checked a couple of references, but I couldn't find the answer. I'm tempted to think that there are no guarantees and that it's left up to each particular implementation.

Thanks.

like image 201
Imbue Avatar asked Feb 09 '09 23:02

Imbue


People also ask

Does multiset maintain order?

Following are the properties of multisets: Stores elements in sorted order. It allows the storage of multiple elements. We can erase more than 1 element by giving the start iterator and end iterator.

Is std :: sort a stable sort?

stable_sort() in C++ STL. stable_sort() is used to sort the elements in the range [first, last) in ascending order. It is like std::sort, but stable_sort() keeps the relative order of elements with equivalent values.

Is multiset always sorted?

Note that this is the largest item in the multiset, because the multiset is always stored in sorted order.

Is multiset sorted in C++?

In case of Set, data is stored in sorted order. In case of MultiSet also the data is stored in sorted order. In Set duplicate values are not allowed to get stored.


1 Answers

This thread implies that it is not guaranteed by the current standard but is met by all known current implementations, and gives a link to the C++0x draft standard that includes a guarantee.

like image 64
Mark Ransom Avatar answered Nov 22 '22 01:11

Mark Ransom