Re: question on map< list<T>::iterator, int>
On Sat, 03 May 2008 14:48:01 +0200, subramanian100in@yahoo.com, India =
<subramanian100in@yahoo.com> wrote:
Consider the program x.cpp :
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
using namespace std;
int main()
{
map<list<int>::iterator, int> m;
list<int> c;
c.push_back(100);
// m[c.begin()] = 10;
return EXIT_SUCCESS;
}
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. 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 ?
Kindly clarify
Thanks
V.Subramanian
A map is alway sorted by <.
To use an objet like a key for a std::map, these objet must have defined=
=
operator<.