"Ali Cehreli" <ac******@yahoo.com> wrote in message
news:pa****************************@yahoo.com...
On Wed, 04 Aug 2004 07:57:18 +0100, John Harrison wrote:
If you insert equal values into a multiset is it specified what order
they will have in the multiset. For instance, what should be the output of
this program, is it defined?
I wasn't able to find that information in the standard as well. My
analyses using g++ had showed that the multimap was preserving the
insertion order.
#include <set>
#include <iostream>
int main()
{
std::multiset<int> m;
m.insert(1);
std::multiset<int>::iterator i = m.insert(1);
if (i == m.begin())
std::cout << "before\n";
else
std::cout << "after\n";
}
FWIW I tested this on two compilers and got "after" both times but I
can't see this issue addressed in the standard anywhere.
There was an earlier thread about this on this newsgroup. Search for a
thread titled "Insertion order of multimap" that was posted on March 11,
2004. The thread doesn't answer your question but still...
Ali
Thanks for the reference to the other thread. I guess the answer is that
currently it is implementation defined.
Pete Becker's point 'If you care about the order of things with the same key
then you've made a mistake: they should have different keys.' doesn't apply
to my case since unusually I am using a multimap with mutable keys and I
want to add duplicate values and then modify the keys subsequently. Its
simplifies the code if I can guarantee an order but I guess I can't.
john