I'm just gonna describe how to reproduce this problem:
I needed a map whose key is a tuple, and value is an integer. So I wrote this:
map<tuple<string, int>, int> someMap;
And I added one tuple to this someMap
:
tuple<string, int> aTestTuple = make_tuple("whatever", 0);
someMap.insert(make_pair(aTestTuple, 2));
Everything so far was fine, until I wanted to get some value by key:
int test = someMap[aTestTuple];
The compiler in Xcode (5.0.2) complained:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/map:1276:29:
Call to member function '__construct_node' is ambiguous
Four candidates were found in the map
header file:
//////////////////// CANDIDATE 1 ///////////////////////
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__node_holder __construct_node();
template <class _A0>
typename enable_if
<
is_constructible<value_type, _A0>::value,
__node_holder
>::type
__construct_node(_A0&& __a0);
//////////////////// CANDIDATE 2 ///////////////////////
template <class _A0>
typename enable_if
<
is_constructible<key_type, _A0>::value,
__node_holder
>::type
__construct_node(_A0&& __a0);
//////////////////// CANDIDATE 3 ///////////////////////
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class _A0, class _A1, class ..._Args>
__node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
#endif // _LIBCPP_HAS_NO_VARIADICS
//////////////////// CANDIDATE 4 ///////////////////////
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
__node_holder __construct_node(const key_type& __k);
#endif
__node_base_pointer&
__find_equal_key(__node_base_pointer& __parent, const key_type& __k);
__node_base_pointer&
__find_equal_key(const_iterator __hint,
__node_base_pointer& __parent, const key_type& __k);
__node_base_const_pointer
__find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
So the question is: What should I do if I want to index a map
by tuple
s in C++?