Consider the following code. A tuple consisting of integer and vector of integer is defined as the key of a map. However, I was surprised that the compiler does not throw any error when inserting or looking for a tuple consisting of integer and integer as the key. How can this be, since the second element of the tuple should be of the type vector of integer?
std::map <boost::tuple<int, vector<int > >, int> test;
std::map <boost::tuple<int, vector<int > >, int>::iterator test_it;
vector <int> t;
t.push_back(4);
test.insert(make_pair(boost::make_tuple(3, t), 4));
test.insert(make_pair(boost::make_tuple(3, 6), 4));
test_it = test.find(boost::make_tuple(3, 7));
if(test_it != test.end())
throw " test is passed";
Seems like a bug in Boost and many C++ standard library implementations. The problem is shared by both
pair
andtuple
. The simplest code to demonstrate it is:Clang 4.0 with
libc++
and the other one accepts this, Comeau Online accepts it too. GCC 4.7.1 gives an error.It must not compile, according to: