std::set - sorting order specified?

G

Gernot Frisch

Hi,

is the sorting order of std::set / std::map defined? i.e. is the
*begin() of std::set<int> always smaller than *(--end()) ?
 
I

Ivan Vecerina

: Gernot Frisch wrote:
: > i.e. is the *begin() of std::set<int> always smaller than *(--end()) ?
:
: No. --end() shoudn't work at all.

But it will, for UDT with a defined prefix operator--.
Just not for raw pointers...

Ivan
 
N

Neelesh Bodas

Rolf said:
No. --end() shoudn't work at all.

This code compiles and runs well :

#include <iostream>
#include <set>
using namespace std;

int main()
{
set<int> a;
a.insert(1);
a.insert(2);
a.insert(3);
cout << (*(--a.end())) << endl;
}

Am I missing something?
 
G

Gernot Frisch

This code compiles and runs well :

#include <iostream>
#include <set>
using namespace std;

int main()
{
set<int> a;
a.insert(1);
a.insert(2);
a.insert(3);
cout << (*(--a.end())) << endl;
}

Why shouldn't it work? end() is an iterator, which has an -- operator,
that returns an iterator, which has an * operator returning a
reference to the item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top