简体   繁体   中英

Unordered_Set of iterators is throwing weird error

I need to go through a map and get a set of entries I must delete before next iteration. I am trying to use an unordered_set of iterators to store the iterators to these entries.

unordered_set < map<int,int>::iterator > todel;

I get the following super weird and long error.

Can someone tell me what is going on and how to rectify it?

Line 22: Char 50: fatal error: call to implicitly-deleted default constructor of 'unordered_set<map<int, int>::iterator>' (aka 'unordered_set<_Rb_tree_iterator<std::pair<const int, int> > >')
        unordered_set < map<int,int>::iterator > todel;
                                                 ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/unordered_set.h:135:7: note: explicitly defaulted function was implicitly deleted here
      unordered_set() = default;
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/unordered_set.h:100:18: note: default constructor of 'unordered_set<std::_Rb_tree_iterator<std::pair<const int, int> >, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::equal_to<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::allocator<std::_Rb_tree_iterator<std::pair<const int, int> > > >' is implicitly deleted because field '_M_h' has a deleted default constructor
      _Hashtable _M_h;
                 ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable.h:408:7: note: explicitly defaulted function was implicitly deleted here
      _Hashtable() = default;
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable.h:174:7: note: default constructor of '_Hashtable<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::allocator<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Identity, std::equal_to<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true> >' is implicitly deleted because base class '__detail::_Hashtable_base<_Rb_tree_iterator<pair<const int, int> >, _Rb_tree_iterator<pair<const int, int> >, _Identity, equal_to<_Rb_tree_iterator<pair<const int, int> > >, hash<_Rb_tree_iterator<pair<const int, int> > >, _Mod_range_hashing, _Default_ranged_hash, _Hashtable_traits<true, true, true> >' has a deleted default constructor
    : public __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1824:5: note: explicitly defaulted function was implicitly deleted here
    _Hashtable_base() = default;
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1773:5: note: default constructor of '_Hashtable_base<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::__detail::_Identity, std::equal_to<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, true, true> >' is implicitly deleted because base class '_Hash_code_base<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::__detail::_Identity, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, _Hashtable_traits<true, true, true>::__hash_cached::value>' has a deleted default constructor
  : public _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1379:7: note: explicitly defaulted function was implicitly deleted here
      _Hash_code_base() = default;
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1355:7: note: default constructor of '_Hash_code_base<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::__detail::_Identity, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>' is implicitly deleted because base class '_Hashtable_ebo_helper<1, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > > >' has a deleted default constructor
      private _Hashtable_ebo_helper<1, _H1>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1106:7: note: explicitly defaulted function was implicitly deleted here
      _Hashtable_ebo_helper() = default;
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1104:7: note: default constructor of '_Hashtable_ebo_helper<1, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, true>' is implicitly deleted because base class 'std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >' has a deleted default constructor
    : private _Tp
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/functional_hash.h:101:19: note: default constructor of 'hash<std::_Rb_tree_iterator<std::pair<const int, int> > >' is implicitly deleted because base class '__hash_enum<std::_Rb_tree_iterator<std::pair<const int, int> > >' has no default constructor
    struct hash : __hash_enum<_Tp>
                  ^
1 error generated.

std::unordered_set<T> requires T to be hashable, which is not true for std::map<K,V>::iterator . You can use std::set<T> for this cause which require T to have comparison operator< instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM