2016-07-29 3 views
0

std::unordered_map<boost::any, boost::any> 변수를 선언하면 성가신 컴파일 오류가 발생합니다. 예를 들어 std :: unordered_map <boost :: any, boost :: any>는 성가신 컴파일 오류를 던졌습니다

, any.cc :

#include <map> 
#include <boost/any.hpp> 

int main() { 
    std::map<boost::any, boost::any> dict; 
    return 0; 
} 

g++ any.cc -std=c++11 -I/usr/include/boost로 위의 코드를 컴파일은 다음과 같이 오류가 많이 발생합니다

In file included from /usr/include/c++/5/bits/hashtable.h:35:0, 
       from /usr/include/c++/5/unordered_map:47, 
       from any.cc:1: 
/usr/include/c++/5/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> >’: 
/usr/include/c++/5/type_traits:137:12: required from ‘struct std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > >’ 
/usr/include/c++/5/type_traits:148:38: required from ‘struct std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
/usr/include/c++/5/bits/unordered_map.h:100:66: required from ‘class std::unordered_map<boost::any, boost::any>’ 
any.cc:5:48: required from here 
/usr/include/c++/5/bits/hashtable_policy.h:85:34: error: no match for call to ‘(const std::hash<boost::any>) (const boost::any&)’ 
    noexcept(declval<const _Hash&>()(declval<const _Key&>()))> 
           ^
In file included from /usr/include/c++/5/bits/move.h:57:0, 
       from /usr/include/c++/5/bits/stl_pair.h:59, 
       from /usr/include/c++/5/utility:70, 
       from /usr/include/c++/5/unordered_map:38, 
       from any.cc:1: 
/usr/include/c++/5/type_traits: In instantiation of ‘struct std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’: 
/usr/include/c++/5/bits/unordered_map.h:100:66: required from ‘class std::unordered_map<boost::any, boost::any>’ 
any.cc:5:48: required from here 
/usr/include/c++/5/type_traits:148:38: error: ‘value’ is not a member of ‘std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > >’ 
    : public integral_constant<bool, !_Pp::value> 
            ^
In file included from /usr/include/c++/5/unordered_map:48:0, 
       from any.cc:1: 
/usr/include/c++/5/bits/unordered_map.h: In instantiation of ‘class std::unordered_map<boost::any, boost::any>’: 
any.cc:5:48: required from here 
/usr/include/c++/5/bits/unordered_map.h:100:66: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef __umap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc> _Hashtable; 
                   ^
/usr/include/c++/5/bits/unordered_map.h:107:45: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::key_type key_type; 
              ^
/usr/include/c++/5/bits/unordered_map.h:108:47: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::value_type value_type; 
              ^
/usr/include/c++/5/bits/unordered_map.h:109:48: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::mapped_type mapped_type; 
               ^
/usr/include/c++/5/bits/unordered_map.h:110:43: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::hasher hasher; 
             ^
/usr/include/c++/5/bits/unordered_map.h:111:46: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::key_equal key_equal; 
              ^
/usr/include/c++/5/bits/unordered_map.h:112:51: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::allocator_type allocator_type; 
               ^
/usr/include/c++/5/bits/unordered_map.h:117:45: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::pointer pointer; 
              ^
/usr/include/c++/5/bits/unordered_map.h:118:50: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::const_pointer const_pointer; 
               ^
/usr/include/c++/5/bits/unordered_map.h:119:47: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::reference reference; 
              ^
/usr/include/c++/5/bits/unordered_map.h:120:52: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::const_reference const_reference; 
                ^
/usr/include/c++/5/bits/unordered_map.h:121:46: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::iterator iterator; 
              ^
/usr/include/c++/5/bits/unordered_map.h:122:51: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::const_iterator const_iterator; 
               ^
/usr/include/c++/5/bits/unordered_map.h:123:51: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::local_iterator local_iterator; 
               ^
/usr/include/c++/5/bits/unordered_map.h:124:57: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::const_local_iterator const_local_iterator; 
                 ^
/usr/include/c++/5/bits/unordered_map.h:125:47: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::size_type size_type; 
              ^
/usr/include/c++/5/bits/unordered_map.h:126:52: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     typedef typename _Hashtable::difference_type difference_type; 
                ^
/usr/include/c++/5/bits/unordered_map.h:280:7: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     operator=(initializer_list<value_type> __l) 
    ^
/usr/include/c++/5/bits/unordered_map.h:379:2: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
    emplace(_Args&&... __args) 
^
/usr/include/c++/5/bits/unordered_map.h:432:7: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     insert(const value_type& __x) 
    ^
/usr/include/c++/5/bits/unordered_map.h:439:2: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
    insert(_Pair&& __x) 
^
/usr/include/c++/5/bits/unordered_map.h:499:7: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     insert(initializer_list<value_type> __l) 
    ^
/usr/include/c++/5/bits/unordered_map.h:645:7: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     equal_range(const key_type& __x) 
    ^
/usr/include/c++/5/bits/unordered_map.h:649:7: error: ‘value’ is not a member of ‘std::__not_<std::__and_<std::__is_fast_hash<std::hash<boost::any> >, std::__detail::__is_noexcept_hash<boost::any, std::hash<boost::any> > > >’ 
     equal_range(const key_type& __x) const 
    ^

을하지만 std보다는 boost::unordered_map를 사용하는 경우, 어떤 오류없이 작동합니다.

왜?

+0

나는 메시지가 아주 거대하다는 것을 알고 있습니다. 당장 포기할 유혹을 느끼지 만, 대개 이러한 오류가있는 키는 인식하지 못하거나 묻지 않은 유형을 찾는 것입니다. 이 글을 조금 읽었 으면'std :: hash'에 대한 참조를 보게 될 것입니다. 코드를 작성하지 않았으므로'map'이 그것을 사용하려고 시도하고 있음을 나타냅니다. –

+0

@underscore_d 좋아, 나는 당신의 의견처럼 혼란스럽고 열심히 노력하지 않았다는 것을 알고있다. 감사. – signal

답변

4

std::unordered_map은 기본 해 셔로 std::hash을 사용합니다. boost::any에 대해서는 std::hash의 전문화가 없습니다. STanDard 라이브러리는 타사 라이브러리의 엔티티에 대해 아무 것도 모르기 때문에.

boost::unordered_map은 부스트 ​​라이브러리의 유형을 전문으로하는 기본 해셔로 boost::hash을 사용합니다.

해결 방법 : 명시 적으로 std::unordered_mapboost::hash<boost::any>을 hasher로 사용하십시오.

+0

고맙습니다. 내가 이해하는 데 도움이된다. – signal

1

unordered_map<Key, Value>을 선언 할 때 해시 기능이 필요합니다. 기본 해싱 함수는 const hash<Key>(const Key&)입니다.

boost::any, 해당 해싱 템플릿 전문화가 있지만, boost::hash입니다.

따라서 실제로 컴파일러는 에 대한 전문화를 찾으려고 시도하지만 boost::hash 전문화 만 찾습니다.

+0

친절한 대답에 감사드립니다. – signal

관련 문제