Map indexed by tuples in VC ++

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 does not work in VC ++ 2010, but compiles in gcc 4.5 (without warning with -Wall and -pedantic). The error is somewhere inside <tuple>and hard to decipher.

If std::tuplechanged to std::pair, everything will work. What's going on here?

+3
source share
2 answers

error in Visual C ++ 2010 when used std::tupleas a key type in an associative container (for example, std::map).

The workaround (mentioned in the linked bug report) is to create a temporary std::tuple:

m[K(key)] = 1;
+4
source

N3242, 20.4.2.7 [tuple.rel] .

#include <map>, lib++.

+1

All Articles