Re: question on map< list<T>::iterator, int>
On May 3, 2:48 pm, "subramanian10...@yahoo.com, India"
Consider the program x.cpp :
using namespace std;
map<list<int>::iterator, int> m;
// m[c.begin()] = 10;
This program compiles fine with the command
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
However if I remove the comment, I get compilation error because
operator '<' is not defined for list<T>::iterator. Why doesn't the
compiler give this error for
'map<list<int>::iterator, int> m;' itself.
G++ does, if you give it the proper options. Try adding
-D_GLIBCXX_CONCEPT_CHECKS, for example. (This is with g++ 4.1.
I've heard that the option is not necessary with some later
versions, or at least with some builds of some later versions.)
Not providing the ordering relationship is undefined behavior,
howver, and a compiler is not required to diagnose it. Not all
That is, in this first statement inside main() itself, the
compiler can know that the less- than operator cannot be
defined for the key type. So, why does the compiler wait for
an element to be pushed on to the map to flag the error ?
Because it can? The standard doesn't require a diagnostic.
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34