Reputation: 38644
Consider the following code:
#include <tuple>
template <typename Map, typename K>
void mymapfunc(Map& m, const K& key)
{
m[key] = 1;
}
void f()
{
typedef std::tuple<int,int> Pair;
std::map<Pair,int> m;
mymapfunc(m, Pair(1,2));
}
This code fails in VC++ 2010, but compiles fine in gcc 4.5 (without warnings with -Wall and -pedantic). The error is somewhere inside <tuple>
and hard to decipher.
If std::tuple
is changed to std::pair
, everything works. What is going on here?
Upvotes: 3
Views: 951
Reputation: 218900
N3242, 20.4.2.7 [tuple.rel] defines the relational operators for tuple.
If you add #include <map>
, this example also compiles fine in libc++.
Upvotes: 1
Reputation: 355079
There is a bug in Visual C++ 2010 when using a std::tuple
as a key type in an associative container (like std::map
).
The workaround (mentioned in the linked bug report) is to construct a temporary std::tuple
:
m[K(key)] = 1;
Upvotes: 4