473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

simple multiset question

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?

#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.

john
Jul 22 '05 #1
3 1485
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

Jul 22 '05 #2

"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
Jul 22 '05 #3
>
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


I meant multiset.

john
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Arthur J. O'Dwyer | last post by:
I'm seeing a bug at the moment that I can't track down. It's part of a moderately large program, but here is a small program that exhibits the bug on gcc. (The program code follows at the bottom...
1
by: SUPER_SOCKO | last post by:
I am new to STL. I don't know how to access a multiset of a list. My code is the following: #include <list> #include <iostream> #include <set> using namespace std;
5
by: Dale Marchand | last post by:
I'm trying to use an object in two different multiset containers, each with it's own sort method. For the most frequently used, I overrode the operator< method in the class, and for the second I...
2
by: =?iso-8859-1?q?Jo=E3o_Correia?= | last post by:
class CScore { public: int L; int C; CScore(int l, int c) { L = l; C = c;
9
by: neil.johnston | last post by:
I have a cut down example program that uses multiset to order some data. The data arrives from various sources and has a time stamp, data with identical timestamps can arrive and due to fifo's and...
2
by: parvtb | last post by:
Thanks for your patience to read the entire post to understand my confusion I have the user-defined class "tools": class tools{ public: tools( ......) {} friend bool operator<...
4
Digital Don
by: Digital Don | last post by:
Hi, I was looking at the MultiSet STL structure with some "less" keyword. I was told that we can use the "MultiSet" STL structure to automatically sort the content. Is it possible to store and...
0
by: MRAB | last post by:
While another thread is talking about an ordered dict, I thought I'd try a simple implementation of a bag/multiset in Python. Comments/ suggestions welcome, etc. class bag(object): def...
3
by: orzeech | last post by:
Hi everyone! I have a following problem: #include<iostream> #include<set> using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.