Я столкнулся со странной проблемой при создании unordeed_set<tuple<int,int>>
. Я пробовал VC ++ 8, gcc3.2, gcc4.3, все имеют одинаковый результат. Я понятия не имею, что не так с кодом, вот мой код:
#include <boost/unordered_set.hpp>
#include <boost/tuple/tuple.hpp>
// For unordered container, the declaration of operator==
#include <boost/tuple/tuple_comparison.hpp>
using namespace std ;
using namespace boost ;
// define of the hash_value funciton for tuple<int, int>
size_t hash_value(tuple<int, int> const& t) {
return get<0>(t) * 10 + get<1>(t) ;
}
int main () {
unordered_set<tuple<int, int>> s ;
tuple<int, int> t ;
s.insert(t) ;
}
Вот сообщение об ошибке компиляции:
1>c:\libs\boost_1_37_0\boost\functional\hash\extensions.hpp(72) : error C2665: 'boost::hash_value' : none of the 16 overloads could convert all the argument types
1> c:\libs\boost_1_37_0\boost\functional\hash\hash.hpp(33): could be 'size_t boost::hash_value(bool)'
1> c:\libs\boost_1_37_0\boost\functional\hash\hash.hpp(34): or 'size_t boost::hash_value(char)'
1> c:\libs\boost_1_37_0\boost\functional\hash\hash.hpp(35): or 'size_t boost::hash_value(unsigned char)'
....
Кажется, компилятор не может видеть определение hash_value(tuple<int, int>)
. Но если я заменю tuple<int, int>
на другой тип данных, такой как struct F{int a, b;}
, и это будет работать. Это действительно странно. Я что-то пропустил? Большое спасибо.