Another day, another compiler/library bug. If you’re unfortunate enough to still be using Visual Studio 2010, don’t use tuples as map keys.
#include <map>
#include <tuple>
#include <utility>
using namespace std;
typedef tuple<int *, int> FooT;
typedef map<FooT, int> MapT;
int main(int, char*[])
{
MapT m;
// put a value in the map
{
FooT f(nullptr, 0);
m[f] = 1337;
}
// retrieve a value
int s;
{
FooT f(nullptr, 0);
auto i = m.find(f);
if (i != m.end())
{
// VS2010 says:
// error C2440: 'initializing' :
// cannot convert from 'const FooT' to 'int *'
s = i->second;
}
}
return 0;
} |
#include <map>
#include <tuple>
#include <utility>
using namespace std;
typedef tuple<int *, int> FooT;
typedef map<FooT, int> MapT;
int main(int, char*[])
{
MapT m;
// put a value in the map
{
FooT f(nullptr, 0);
m[f] = 1337;
}
// retrieve a value
int s;
{
FooT f(nullptr, 0);
auto i = m.find(f);
if (i != m.end())
{
// VS2010 says:
// error C2440: 'initializing' :
// cannot convert from 'const FooT' to 'int *'
s = i->second;
}
}
return 0;
}
This entry was posted on Friday, February 20th, 2015 at 11:08 am and is filed under C++, Programming. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Something odd… if i replace
with either
or
It works fine (compiles and behaves like it should at runtime), even though the error reported by VS when it doesnt work points at the s assignment line!