Unordered_Set 的迭代器抛出奇怪的错误
Unordered_Set of iterators is throwing weird error
我需要遍历地图并获取一组我必须在下一次迭代之前删除的条目。我正在尝试使用 unordered_set 迭代器将迭代器存储到这些条目。
unordered_set < map<int,int>::iterator > todel;
我得到以下超级奇怪的长错误。
有人能告诉我这是怎么回事以及如何纠正吗?
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>
要求 T 是可散列的,而 std::map<K,V>::iterator
则不是这样。您可以为此使用 std::set<T>
,这需要 T 进行比较 operator<
。
我需要遍历地图并获取一组我必须在下一次迭代之前删除的条目。我正在尝试使用 unordered_set 迭代器将迭代器存储到这些条目。
unordered_set < map<int,int>::iterator > todel;
我得到以下超级奇怪的长错误。
有人能告诉我这是怎么回事以及如何纠正吗?
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>
要求 T 是可散列的,而 std::map<K,V>::iterator
则不是这样。您可以为此使用 std::set<T>
,这需要 T 进行比较 operator<
。