2 // Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
3 // Copyright (C) 2005-2011 Daniel James.
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/unordered for documentation
9 #ifndef BOOST_UNORDERED_UNORDERED_SET_HPP_INCLUDED
10 #define BOOST_UNORDERED_UNORDERED_SET_HPP_INCLUDED
12 #include <boost/config.hpp>
13 #if defined(BOOST_HAS_PRAGMA_ONCE)
17 #include <boost/core/explicit_operator_bool.hpp>
18 #include <boost/functional/hash.hpp>
19 #include <boost/move/move.hpp>
20 #include <boost/unordered/detail/set.hpp>
22 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
23 #include <initializer_list>
26 #if defined(BOOST_MSVC)
28 #if BOOST_MSVC >= 1400
29 #pragma warning(disable : 4396) // the inline specifier cannot be used when a
30 // friend declaration refers to a specialization
31 // of a function template
37 template <class T, class H, class P, class A> class unordered_set
39 #if defined(BOOST_UNORDERED_USE_MOVE)
40 BOOST_COPYABLE_AND_MOVABLE(unordered_set)
42 template <typename, typename, typename, typename>
43 friend class unordered_multiset;
50 typedef A allocator_type;
53 typedef boost::unordered::detail::set<A, T, H, P> types;
54 typedef typename types::value_allocator_traits value_allocator_traits;
55 typedef typename types::table table;
56 typedef typename table::node_pointer node_pointer;
57 typedef typename table::link_pointer link_pointer;
60 typedef typename value_allocator_traits::pointer pointer;
61 typedef typename value_allocator_traits::const_pointer const_pointer;
63 typedef value_type& reference;
64 typedef value_type const& const_reference;
66 typedef std::size_t size_type;
67 typedef std::ptrdiff_t difference_type;
69 typedef typename table::iterator iterator;
70 typedef typename table::c_iterator const_iterator;
71 typedef typename table::l_iterator local_iterator;
72 typedef typename table::cl_iterator const_local_iterator;
73 typedef typename types::node_type node_type;
74 typedef typename types::insert_return_type insert_return_type;
84 explicit unordered_set(size_type, const hasher& = hasher(),
85 const key_equal& = key_equal(),
86 const allocator_type& = allocator_type());
88 template <class InputIt>
89 unordered_set(InputIt, InputIt,
90 size_type = boost::unordered::detail::default_bucket_count,
91 const hasher& = hasher(), const key_equal& = key_equal(),
92 const allocator_type& = allocator_type());
94 unordered_set(unordered_set const&);
96 #if defined(BOOST_UNORDERED_USE_MOVE) || \
97 !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
98 unordered_set(BOOST_RV_REF(unordered_set) other)
99 BOOST_NOEXCEPT_IF(table::nothrow_move_constructible)
100 : table_(other.table_, boost::unordered::detail::move_tag())
102 // The move is done in table_
106 explicit unordered_set(allocator_type const&);
108 unordered_set(unordered_set const&, allocator_type const&);
110 unordered_set(BOOST_RV_REF(unordered_set), allocator_type const&);
112 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
113 unordered_set(std::initializer_list<value_type>,
114 size_type = boost::unordered::detail::default_bucket_count,
115 const hasher& = hasher(), const key_equal& l = key_equal(),
116 const allocator_type& = allocator_type());
119 explicit unordered_set(size_type, const allocator_type&);
121 explicit unordered_set(size_type, const hasher&, const allocator_type&);
123 template <class InputIt>
124 unordered_set(InputIt, InputIt, size_type, const allocator_type&);
126 template <class InputIt>
128 InputIt, InputIt, size_type, const hasher&, const allocator_type&);
130 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
132 std::initializer_list<value_type>, size_type, const allocator_type&);
134 unordered_set(std::initializer_list<value_type>, size_type, const hasher&,
135 const allocator_type&);
140 ~unordered_set() BOOST_NOEXCEPT;
144 #if defined(BOOST_UNORDERED_USE_MOVE)
145 unordered_set& operator=(BOOST_COPY_ASSIGN_REF(unordered_set) x)
147 table_.assign(x.table_, boost::unordered::detail::true_type());
151 unordered_set& operator=(BOOST_RV_REF(unordered_set) x)
152 // C++17 support: BOOST_NOEXCEPT_IF(
153 // value_allocator_traits::is_always_equal::value &&
154 // is_nothrow_move_assignable_v<H> &&
155 // is_nothrow_move_assignable_v<P>)
157 table_.move_assign(x.table_, boost::unordered::detail::true_type());
161 unordered_set& operator=(unordered_set const& x)
163 table_.assign(x.table_, boost::unordered::detail::true_type());
167 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
168 unordered_set& operator=(unordered_set&& x)
169 // C++17 support: BOOST_NOEXCEPT_IF(
170 // value_allocator_traits::is_always_equal::value &&
171 // is_nothrow_move_assignable_v<H> &&
172 // is_nothrow_move_assignable_v<P>)
174 table_.move_assign(x.table_, boost::unordered::detail::true_type());
180 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
181 unordered_set& operator=(std::initializer_list<value_type>);
184 allocator_type get_allocator() const BOOST_NOEXCEPT
186 return table_.node_alloc();
191 iterator begin() BOOST_NOEXCEPT { return iterator(table_.begin()); }
193 const_iterator begin() const BOOST_NOEXCEPT
195 return const_iterator(table_.begin());
198 iterator end() BOOST_NOEXCEPT { return iterator(); }
200 const_iterator end() const BOOST_NOEXCEPT { return const_iterator(); }
202 const_iterator cbegin() const BOOST_NOEXCEPT
204 return const_iterator(table_.begin());
207 const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(); }
211 bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; }
213 size_type size() const BOOST_NOEXCEPT { return table_.size_; }
215 size_type max_size() const BOOST_NOEXCEPT;
219 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
221 template <class... Args>
222 std::pair<iterator, bool> emplace(BOOST_FWD_REF(Args)... args)
224 return table_.emplace_unique(
225 table::extractor::extract(boost::forward<Args>(args)...),
226 boost::forward<Args>(args)...);
231 #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
233 // 0 argument emplace requires special treatment in case
234 // the container is instantiated with a value type that
235 // doesn't have a default constructor.
237 std::pair<iterator, bool> emplace(
238 boost::unordered::detail::empty_emplace =
239 boost::unordered::detail::empty_emplace(),
240 value_type v = value_type())
242 return this->emplace(boost::move(v));
247 template <typename A0>
248 std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
250 return table_.emplace_unique(
251 table::extractor::extract(boost::forward<A0>(a0)),
252 boost::unordered::detail::create_emplace_args(
253 boost::forward<A0>(a0)));
256 template <typename A0, typename A1>
257 std::pair<iterator, bool> emplace(
258 BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
260 return table_.emplace_unique(
261 table::extractor::extract(
262 boost::forward<A0>(a0), boost::forward<A1>(a1)),
263 boost::unordered::detail::create_emplace_args(
264 boost::forward<A0>(a0), boost::forward<A1>(a1)));
267 template <typename A0, typename A1, typename A2>
268 std::pair<iterator, bool> emplace(
269 BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
271 return table_.emplace_unique(
272 table::extractor::extract(
273 boost::forward<A0>(a0), boost::forward<A1>(a1)),
274 boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
275 boost::forward<A1>(a1), boost::forward<A2>(a2)));
280 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
282 template <class... Args>
283 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
285 return table_.emplace_hint_unique(hint,
286 table::extractor::extract(boost::forward<Args>(args)...),
287 boost::forward<Args>(args)...);
292 #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
294 iterator emplace_hint(const_iterator hint,
295 boost::unordered::detail::empty_emplace =
296 boost::unordered::detail::empty_emplace(),
297 value_type v = value_type())
299 return this->emplace_hint(hint, boost::move(v));
304 template <typename A0>
305 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0)
307 return table_.emplace_hint_unique(hint,
308 table::extractor::extract(boost::forward<A0>(a0)),
309 boost::unordered::detail::create_emplace_args(
310 boost::forward<A0>(a0)));
313 template <typename A0, typename A1>
314 iterator emplace_hint(
315 const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
317 return table_.emplace_hint_unique(hint,
318 table::extractor::extract(
319 boost::forward<A0>(a0), boost::forward<A1>(a1)),
320 boost::unordered::detail::create_emplace_args(
321 boost::forward<A0>(a0), boost::forward<A1>(a1)));
324 template <typename A0, typename A1, typename A2>
325 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0,
326 BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
328 return table_.emplace_hint_unique(hint,
329 table::extractor::extract(
330 boost::forward<A0>(a0), boost::forward<A1>(a1)),
331 boost::unordered::detail::create_emplace_args(boost::forward<A0>(a0),
332 boost::forward<A1>(a1), boost::forward<A2>(a2)));
337 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
339 #define BOOST_UNORDERED_EMPLACE(z, n, _) \
340 template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
341 std::pair<iterator, bool> emplace( \
342 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
344 return table_.emplace_unique( \
345 table::extractor::extract( \
346 boost::forward<A0>(a0), boost::forward<A1>(a1)), \
347 boost::unordered::detail::create_emplace_args( \
348 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
351 template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
352 iterator emplace_hint( \
353 const_iterator hint, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
355 return table_.emplace_hint_unique(hint, \
356 table::extractor::extract( \
357 boost::forward<A0>(a0), boost::forward<A1>(a1)), \
358 boost::unordered::detail::create_emplace_args( \
359 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))); \
362 BOOST_UNORDERED_EMPLACE(1, 4, _)
363 BOOST_UNORDERED_EMPLACE(1, 5, _)
364 BOOST_UNORDERED_EMPLACE(1, 6, _)
365 BOOST_UNORDERED_EMPLACE(1, 7, _)
366 BOOST_UNORDERED_EMPLACE(1, 8, _)
367 BOOST_UNORDERED_EMPLACE(1, 9, _)
368 BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
369 BOOST_UNORDERED_EMPLACE, _)
371 #undef BOOST_UNORDERED_EMPLACE
375 std::pair<iterator, bool> insert(value_type const& x)
377 return this->emplace(x);
380 std::pair<iterator, bool> insert(BOOST_UNORDERED_RV_REF(value_type) x)
382 return this->emplace(boost::move(x));
385 iterator insert(const_iterator hint, value_type const& x)
387 return this->emplace_hint(hint, x);
390 iterator insert(const_iterator hint, BOOST_UNORDERED_RV_REF(value_type) x)
392 return this->emplace_hint(hint, boost::move(x));
395 template <class InputIt> void insert(InputIt, InputIt);
397 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
398 void insert(std::initializer_list<value_type>);
403 node_type extract(const_iterator position)
406 table_.extract_by_iterator_unique(position), table_.node_alloc());
409 node_type extract(const key_type& k)
411 return node_type(table_.extract_by_key(k), table_.node_alloc());
414 insert_return_type insert(BOOST_RV_REF(node_type) np)
416 insert_return_type result;
417 table_.move_insert_node_type_unique(np, result);
418 return boost::move(result);
421 iterator insert(const_iterator hint, BOOST_RV_REF(node_type) np)
423 return table_.move_insert_node_type_with_hint_unique(hint, np);
426 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
427 (BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 6, 0))
429 // Note: Use r-value node_type to insert.
430 insert_return_type insert(node_type&);
431 iterator insert(const_iterator, node_type& np);
436 iterator erase(const_iterator);
437 size_type erase(const key_type&);
438 iterator erase(const_iterator, const_iterator);
439 BOOST_UNORDERED_DEPRECATED("Use erase instead")
440 void quick_erase(const_iterator it) { erase(it); }
441 BOOST_UNORDERED_DEPRECATED("Use erase instead")
442 void erase_return_void(const_iterator it) { erase(it); }
444 void swap(unordered_set&);
445 // C++17 support: BOOST_NOEXCEPT_IF(
446 // value_allocator_traits::is_always_equal::value &&
447 // is_nothrow_move_assignable_v<H> &&
448 // is_nothrow_move_assignable_v<P>)
449 void clear() BOOST_NOEXCEPT { table_.clear_impl(); }
451 template <typename H2, typename P2>
452 void merge(boost::unordered_set<T, H2, P2, A>& source);
454 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
455 template <typename H2, typename P2>
456 void merge(boost::unordered_set<T, H2, P2, A>&& source);
459 template <typename H2, typename P2>
460 void merge(boost::unordered_multiset<T, H2, P2, A>& source);
462 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
463 template <typename H2, typename P2>
464 void merge(boost::unordered_multiset<T, H2, P2, A>&& source);
469 hasher hash_function() const;
470 key_equal key_eq() const;
474 const_iterator find(const key_type&) const;
476 template <class CompatibleKey, class CompatibleHash,
477 class CompatiblePredicate>
478 const_iterator find(CompatibleKey const&, CompatibleHash const&,
479 CompatiblePredicate const&) const;
481 size_type count(const key_type&) const;
483 std::pair<const_iterator, const_iterator> equal_range(
484 const key_type&) const;
488 size_type bucket_count() const BOOST_NOEXCEPT
490 return table_.bucket_count_;
493 size_type max_bucket_count() const BOOST_NOEXCEPT
495 return table_.max_bucket_count();
498 size_type bucket_size(size_type) const;
500 size_type bucket(const key_type& k) const
502 return table_.hash_to_bucket(table_.hash(k));
505 local_iterator begin(size_type n)
507 return local_iterator(table_.begin(n), n, table_.bucket_count_);
510 const_local_iterator begin(size_type n) const
512 return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
515 local_iterator end(size_type) { return local_iterator(); }
517 const_local_iterator end(size_type) const
519 return const_local_iterator();
522 const_local_iterator cbegin(size_type n) const
524 return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
527 const_local_iterator cend(size_type) const
529 return const_local_iterator();
534 float load_factor() const BOOST_NOEXCEPT;
535 float max_load_factor() const BOOST_NOEXCEPT { return table_.mlf_; }
536 void max_load_factor(float) BOOST_NOEXCEPT;
537 void rehash(size_type);
538 void reserve(size_type);
540 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
541 friend bool operator==
542 <T, H, P, A>(unordered_set const&, unordered_set const&);
543 friend bool operator!=
544 <T, H, P, A>(unordered_set const&, unordered_set const&);
546 }; // class template unordered_set
548 template <class T, class H, class P, class A> class unordered_multiset
550 #if defined(BOOST_UNORDERED_USE_MOVE)
551 BOOST_COPYABLE_AND_MOVABLE(unordered_multiset)
553 template <typename, typename, typename, typename>
554 friend class unordered_set;
558 typedef T value_type;
561 typedef A allocator_type;
564 typedef boost::unordered::detail::set<A, T, H, P> types;
565 typedef typename types::value_allocator_traits value_allocator_traits;
566 typedef typename types::table table;
567 typedef typename table::node_pointer node_pointer;
568 typedef typename table::link_pointer link_pointer;
571 typedef typename value_allocator_traits::pointer pointer;
572 typedef typename value_allocator_traits::const_pointer const_pointer;
574 typedef value_type& reference;
575 typedef value_type const& const_reference;
577 typedef std::size_t size_type;
578 typedef std::ptrdiff_t difference_type;
580 typedef typename table::iterator iterator;
581 typedef typename table::c_iterator const_iterator;
582 typedef typename table::l_iterator local_iterator;
583 typedef typename table::cl_iterator const_local_iterator;
584 typedef typename types::node_type node_type;
592 unordered_multiset();
594 explicit unordered_multiset(size_type, const hasher& = hasher(),
595 const key_equal& = key_equal(),
596 const allocator_type& = allocator_type());
598 template <class InputIt>
599 unordered_multiset(InputIt, InputIt,
600 size_type = boost::unordered::detail::default_bucket_count,
601 const hasher& = hasher(), const key_equal& = key_equal(),
602 const allocator_type& = allocator_type());
604 unordered_multiset(unordered_multiset const&);
606 #if defined(BOOST_UNORDERED_USE_MOVE) || \
607 !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
608 unordered_multiset(BOOST_RV_REF(unordered_multiset) other)
609 BOOST_NOEXCEPT_IF(table::nothrow_move_constructible)
610 : table_(other.table_, boost::unordered::detail::move_tag())
612 // The move is done in table_
616 explicit unordered_multiset(allocator_type const&);
618 unordered_multiset(unordered_multiset const&, allocator_type const&);
621 BOOST_RV_REF(unordered_multiset), allocator_type const&);
623 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
624 unordered_multiset(std::initializer_list<value_type>,
625 size_type = boost::unordered::detail::default_bucket_count,
626 const hasher& = hasher(), const key_equal& l = key_equal(),
627 const allocator_type& = allocator_type());
630 explicit unordered_multiset(size_type, const allocator_type&);
632 explicit unordered_multiset(
633 size_type, const hasher&, const allocator_type&);
635 template <class InputIt>
636 unordered_multiset(InputIt, InputIt, size_type, const allocator_type&);
638 template <class InputIt>
640 InputIt, InputIt, size_type, const hasher&, const allocator_type&);
642 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
644 std::initializer_list<value_type>, size_type, const allocator_type&);
646 unordered_multiset(std::initializer_list<value_type>, size_type,
647 const hasher&, const allocator_type&);
652 ~unordered_multiset() BOOST_NOEXCEPT;
656 #if defined(BOOST_UNORDERED_USE_MOVE)
657 unordered_multiset& operator=(BOOST_COPY_ASSIGN_REF(unordered_multiset) x)
659 table_.assign(x.table_, boost::unordered::detail::false_type());
663 unordered_multiset& operator=(BOOST_RV_REF(unordered_multiset) x)
664 // C++17 support: BOOST_NOEXCEPT_IF(
665 // value_allocator_traits::is_always_equal::value &&
666 // is_nothrow_move_assignable_v<H> &&
667 // is_nothrow_move_assignable_v<P>)
669 table_.move_assign(x.table_, boost::unordered::detail::false_type());
673 unordered_multiset& operator=(unordered_multiset const& x)
675 table_.assign(x.table_, boost::unordered::detail::false_type());
679 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
680 unordered_multiset& operator=(unordered_multiset&& x)
681 // C++17 support: BOOST_NOEXCEPT_IF(
682 // value_allocator_traits::is_always_equal::value &&
683 // is_nothrow_move_assignable_v<H> &&
684 // is_nothrow_move_assignable_v<P>)
686 table_.move_assign(x.table_, boost::unordered::detail::false_type());
692 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
693 unordered_multiset& operator=(std::initializer_list<value_type>);
696 allocator_type get_allocator() const BOOST_NOEXCEPT
698 return table_.node_alloc();
703 iterator begin() BOOST_NOEXCEPT { return iterator(table_.begin()); }
705 const_iterator begin() const BOOST_NOEXCEPT
707 return const_iterator(table_.begin());
710 iterator end() BOOST_NOEXCEPT { return iterator(); }
712 const_iterator end() const BOOST_NOEXCEPT { return const_iterator(); }
714 const_iterator cbegin() const BOOST_NOEXCEPT
716 return const_iterator(table_.begin());
719 const_iterator cend() const BOOST_NOEXCEPT { return const_iterator(); }
723 bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; }
725 size_type size() const BOOST_NOEXCEPT { return table_.size_; }
727 size_type max_size() const BOOST_NOEXCEPT;
731 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
733 template <class... Args> iterator emplace(BOOST_FWD_REF(Args)... args)
735 return iterator(table_.emplace_equiv(
736 boost::unordered::detail::func::construct_node_from_args(
737 table_.node_alloc(), boost::forward<Args>(args)...)));
742 #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
744 // 0 argument emplace requires special treatment in case
745 // the container is instantiated with a value type that
746 // doesn't have a default constructor.
748 iterator emplace(boost::unordered::detail::empty_emplace =
749 boost::unordered::detail::empty_emplace(),
750 value_type v = value_type())
752 return this->emplace(boost::move(v));
757 template <typename A0> iterator emplace(BOOST_FWD_REF(A0) a0)
759 return iterator(table_.emplace_equiv(
760 boost::unordered::detail::func::construct_node_from_args(
761 table_.node_alloc(), boost::unordered::detail::create_emplace_args(
762 boost::forward<A0>(a0)))));
765 template <typename A0, typename A1>
766 iterator emplace(BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
768 return iterator(table_.emplace_equiv(
769 boost::unordered::detail::func::construct_node_from_args(
771 boost::unordered::detail::create_emplace_args(
772 boost::forward<A0>(a0), boost::forward<A1>(a1)))));
775 template <typename A0, typename A1, typename A2>
777 BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
779 return iterator(table_.emplace_equiv(
780 boost::unordered::detail::func::construct_node_from_args(
782 boost::unordered::detail::create_emplace_args(
783 boost::forward<A0>(a0), boost::forward<A1>(a1),
784 boost::forward<A2>(a2)))));
789 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
791 template <class... Args>
792 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
794 return iterator(table_.emplace_hint_equiv(
795 hint, boost::unordered::detail::func::construct_node_from_args(
796 table_.node_alloc(), boost::forward<Args>(args)...)));
801 #if !BOOST_UNORDERED_SUN_WORKAROUNDS1
803 iterator emplace_hint(const_iterator hint,
804 boost::unordered::detail::empty_emplace =
805 boost::unordered::detail::empty_emplace(),
806 value_type v = value_type())
808 return this->emplace_hint(hint, boost::move(v));
813 template <typename A0>
814 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0)
816 return iterator(table_.emplace_hint_equiv(hint,
817 boost::unordered::detail::func::construct_node_from_args(
818 table_.node_alloc(), boost::unordered::detail::create_emplace_args(
819 boost::forward<A0>(a0)))));
822 template <typename A0, typename A1>
823 iterator emplace_hint(
824 const_iterator hint, BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1)
826 return iterator(table_.emplace_hint_equiv(
827 hint, boost::unordered::detail::func::construct_node_from_args(
829 boost::unordered::detail::create_emplace_args(
830 boost::forward<A0>(a0), boost::forward<A1>(a1)))));
833 template <typename A0, typename A1, typename A2>
834 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(A0) a0,
835 BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
837 return iterator(table_.emplace_hint_equiv(
838 hint, boost::unordered::detail::func::construct_node_from_args(
840 boost::unordered::detail::create_emplace_args(
841 boost::forward<A0>(a0), boost::forward<A1>(a1),
842 boost::forward<A2>(a2)))));
847 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
849 #define BOOST_UNORDERED_EMPLACE(z, n, _) \
850 template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
851 iterator emplace(BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
853 return iterator(table_.emplace_equiv( \
854 boost::unordered::detail::func::construct_node_from_args( \
855 table_.node_alloc(), \
856 boost::unordered::detail::create_emplace_args( \
857 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))))); \
860 template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
861 iterator emplace_hint( \
862 const_iterator hint, BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a)) \
864 return iterator(table_.emplace_hint_equiv( \
865 hint, boost::unordered::detail::func::construct_node_from_args( \
866 table_.node_alloc(), \
867 boost::unordered::detail::create_emplace_args( \
868 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, a))))); \
871 BOOST_UNORDERED_EMPLACE(1, 4, _)
872 BOOST_UNORDERED_EMPLACE(1, 5, _)
873 BOOST_UNORDERED_EMPLACE(1, 6, _)
874 BOOST_UNORDERED_EMPLACE(1, 7, _)
875 BOOST_UNORDERED_EMPLACE(1, 8, _)
876 BOOST_UNORDERED_EMPLACE(1, 9, _)
877 BOOST_PP_REPEAT_FROM_TO(10, BOOST_PP_INC(BOOST_UNORDERED_EMPLACE_LIMIT),
878 BOOST_UNORDERED_EMPLACE, _)
880 #undef BOOST_UNORDERED_EMPLACE
884 iterator insert(value_type const& x) { return this->emplace(x); }
886 iterator insert(BOOST_UNORDERED_RV_REF(value_type) x)
888 return this->emplace(boost::move(x));
891 iterator insert(const_iterator hint, value_type const& x)
893 return this->emplace_hint(hint, x);
896 iterator insert(const_iterator hint, BOOST_UNORDERED_RV_REF(value_type) x)
898 return this->emplace_hint(hint, boost::move(x));
901 template <class InputIt> void insert(InputIt, InputIt);
903 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
904 void insert(std::initializer_list<value_type>);
909 node_type extract(const_iterator position)
912 table_.extract_by_iterator_equiv(position), table_.node_alloc());
915 node_type extract(const key_type& k)
917 return node_type(table_.extract_by_key(k), table_.node_alloc());
920 iterator insert(BOOST_RV_REF(node_type) np)
922 return table_.move_insert_node_type_equiv(np);
925 iterator insert(const_iterator hint, BOOST_RV_REF(node_type) np)
927 return table_.move_insert_node_type_with_hint_equiv(hint, np);
930 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
931 (BOOST_COMP_GNUC && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(4, 6, 0))
933 // Note: Use r-value node_type to insert.
934 iterator insert(node_type&);
935 iterator insert(const_iterator, node_type& np);
940 iterator erase(const_iterator);
941 size_type erase(const key_type&);
942 iterator erase(const_iterator, const_iterator);
943 BOOST_UNORDERED_DEPRECATED("Use erase instead")
944 void quick_erase(const_iterator it) { erase(it); }
945 BOOST_UNORDERED_DEPRECATED("Use erase instead")
946 void erase_return_void(const_iterator it) { erase(it); }
948 void swap(unordered_multiset&);
949 // C++17 support: BOOST_NOEXCEPT_IF(
950 // value_allocator_traits::is_always_equal::value &&
951 // is_nothrow_move_assignable_v<H> &&
952 // is_nothrow_move_assignable_v<P>)
953 void clear() BOOST_NOEXCEPT { table_.clear_impl(); }
955 template <typename H2, typename P2>
956 void merge(boost::unordered_multiset<T, H2, P2, A>& source);
958 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
959 template <typename H2, typename P2>
960 void merge(boost::unordered_multiset<T, H2, P2, A>&& source);
963 template <typename H2, typename P2>
964 void merge(boost::unordered_set<T, H2, P2, A>& source);
966 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
967 template <typename H2, typename P2>
968 void merge(boost::unordered_set<T, H2, P2, A>&& source);
973 hasher hash_function() const;
974 key_equal key_eq() const;
978 const_iterator find(const key_type&) const;
980 template <class CompatibleKey, class CompatibleHash,
981 class CompatiblePredicate>
982 const_iterator find(CompatibleKey const&, CompatibleHash const&,
983 CompatiblePredicate const&) const;
985 size_type count(const key_type&) const;
987 std::pair<const_iterator, const_iterator> equal_range(
988 const key_type&) const;
992 size_type bucket_count() const BOOST_NOEXCEPT
994 return table_.bucket_count_;
997 size_type max_bucket_count() const BOOST_NOEXCEPT
999 return table_.max_bucket_count();
1002 size_type bucket_size(size_type) const;
1004 size_type bucket(const key_type& k) const
1006 return table_.hash_to_bucket(table_.hash(k));
1009 local_iterator begin(size_type n)
1011 return local_iterator(table_.begin(n), n, table_.bucket_count_);
1014 const_local_iterator begin(size_type n) const
1016 return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
1019 local_iterator end(size_type) { return local_iterator(); }
1021 const_local_iterator end(size_type) const
1023 return const_local_iterator();
1026 const_local_iterator cbegin(size_type n) const
1028 return const_local_iterator(table_.begin(n), n, table_.bucket_count_);
1031 const_local_iterator cend(size_type) const
1033 return const_local_iterator();
1038 float load_factor() const BOOST_NOEXCEPT;
1039 float max_load_factor() const BOOST_NOEXCEPT { return table_.mlf_; }
1040 void max_load_factor(float) BOOST_NOEXCEPT;
1041 void rehash(size_type);
1042 void reserve(size_type);
1044 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582)
1045 friend bool operator==
1046 <T, H, P, A>(unordered_multiset const&, unordered_multiset const&);
1047 friend bool operator!=
1048 <T, H, P, A>(unordered_multiset const&, unordered_multiset const&);
1050 }; // class template unordered_multiset
1052 ////////////////////////////////////////////////////////////////////////////
1053 template <class T, class H, class P, class A>
1054 unordered_set<T, H, P, A>::unordered_set()
1055 : table_(boost::unordered::detail::default_bucket_count, hasher(),
1056 key_equal(), allocator_type())
1060 template <class T, class H, class P, class A>
1061 unordered_set<T, H, P, A>::unordered_set(size_type n, const hasher& hf,
1062 const key_equal& eql, const allocator_type& a)
1063 : table_(n, hf, eql, a)
1067 template <class T, class H, class P, class A>
1068 template <class InputIt>
1069 unordered_set<T, H, P, A>::unordered_set(InputIt f, InputIt l, size_type n,
1070 const hasher& hf, const key_equal& eql, const allocator_type& a)
1071 : table_(boost::unordered::detail::initial_size(f, l, n), hf, eql, a)
1076 template <class T, class H, class P, class A>
1077 unordered_set<T, H, P, A>::unordered_set(unordered_set const& other)
1078 : table_(other.table_,
1079 unordered_set::value_allocator_traits::
1080 select_on_container_copy_construction(other.get_allocator()))
1082 if (other.table_.size_) {
1083 table_.copy_buckets(
1084 other.table_, boost::unordered::detail::true_type());
1088 template <class T, class H, class P, class A>
1089 unordered_set<T, H, P, A>::unordered_set(allocator_type const& a)
1090 : table_(boost::unordered::detail::default_bucket_count, hasher(),
1095 template <class T, class H, class P, class A>
1096 unordered_set<T, H, P, A>::unordered_set(
1097 unordered_set const& other, allocator_type const& a)
1098 : table_(other.table_, a)
1100 if (other.table_.size_) {
1101 table_.copy_buckets(
1102 other.table_, boost::unordered::detail::true_type());
1106 template <class T, class H, class P, class A>
1107 unordered_set<T, H, P, A>::unordered_set(
1108 BOOST_RV_REF(unordered_set) other, allocator_type const& a)
1109 : table_(other.table_, a, boost::unordered::detail::move_tag())
1111 table_.move_construct_buckets(other.table_);
1114 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1116 template <class T, class H, class P, class A>
1117 unordered_set<T, H, P, A>::unordered_set(
1118 std::initializer_list<value_type> list, size_type n, const hasher& hf,
1119 const key_equal& eql, const allocator_type& a)
1121 boost::unordered::detail::initial_size(list.begin(), list.end(), n),
1124 this->insert(list.begin(), list.end());
1129 template <class T, class H, class P, class A>
1130 unordered_set<T, H, P, A>::unordered_set(
1131 size_type n, const allocator_type& a)
1132 : table_(n, hasher(), key_equal(), a)
1136 template <class T, class H, class P, class A>
1137 unordered_set<T, H, P, A>::unordered_set(
1138 size_type n, const hasher& hf, const allocator_type& a)
1139 : table_(n, hf, key_equal(), a)
1143 template <class T, class H, class P, class A>
1144 template <class InputIt>
1145 unordered_set<T, H, P, A>::unordered_set(
1146 InputIt f, InputIt l, size_type n, const allocator_type& a)
1147 : table_(boost::unordered::detail::initial_size(f, l, n), hasher(),
1153 template <class T, class H, class P, class A>
1154 template <class InputIt>
1155 unordered_set<T, H, P, A>::unordered_set(InputIt f, InputIt l, size_type n,
1156 const hasher& hf, const allocator_type& a)
1158 boost::unordered::detail::initial_size(f, l, n), hf, key_equal(), a)
1163 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1165 template <class T, class H, class P, class A>
1166 unordered_set<T, H, P, A>::unordered_set(
1167 std::initializer_list<value_type> list, size_type n,
1168 const allocator_type& a)
1170 boost::unordered::detail::initial_size(list.begin(), list.end(), n),
1171 hasher(), key_equal(), a)
1173 this->insert(list.begin(), list.end());
1176 template <class T, class H, class P, class A>
1177 unordered_set<T, H, P, A>::unordered_set(
1178 std::initializer_list<value_type> list, size_type n, const hasher& hf,
1179 const allocator_type& a)
1181 boost::unordered::detail::initial_size(list.begin(), list.end(), n),
1184 this->insert(list.begin(), list.end());
1189 template <class T, class H, class P, class A>
1190 unordered_set<T, H, P, A>::~unordered_set() BOOST_NOEXCEPT
1194 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1196 template <class T, class H, class P, class A>
1197 unordered_set<T, H, P, A>& unordered_set<T, H, P, A>::operator=(
1198 std::initializer_list<value_type> list)
1201 this->insert(list.begin(), list.end());
1207 // size and capacity
1209 template <class T, class H, class P, class A>
1210 std::size_t unordered_set<T, H, P, A>::max_size() const BOOST_NOEXCEPT
1212 using namespace std;
1214 // size < mlf_ * count
1215 return boost::unordered::detail::double_to_size(
1216 ceil(static_cast<double>(table_.mlf_) *
1217 static_cast<double>(table_.max_bucket_count()))) -
1223 template <class T, class H, class P, class A>
1224 template <class InputIt>
1225 void unordered_set<T, H, P, A>::insert(InputIt first, InputIt last)
1227 if (first != last) {
1228 table_.insert_range_unique(
1229 table::extractor::extract(*first), first, last);
1233 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1234 template <class T, class H, class P, class A>
1235 void unordered_set<T, H, P, A>::insert(
1236 std::initializer_list<value_type> list)
1238 this->insert(list.begin(), list.end());
1242 template <class T, class H, class P, class A>
1243 typename unordered_set<T, H, P, A>::iterator
1244 unordered_set<T, H, P, A>::erase(const_iterator position)
1246 node_pointer node = table::get_node(position);
1248 node_pointer next = table::next_node(node);
1249 table_.erase_nodes_unique(node, next);
1250 return iterator(next);
1253 template <class T, class H, class P, class A>
1254 typename unordered_set<T, H, P, A>::size_type
1255 unordered_set<T, H, P, A>::erase(const key_type& k)
1257 return table_.erase_key_unique(k);
1260 template <class T, class H, class P, class A>
1261 typename unordered_set<T, H, P, A>::iterator
1262 unordered_set<T, H, P, A>::erase(const_iterator first, const_iterator last)
1264 node_pointer last_node = table::get_node(last);
1266 return iterator(last_node);
1267 table_.erase_nodes_unique(table::get_node(first), last_node);
1268 return iterator(last_node);
1271 template <class T, class H, class P, class A>
1272 void unordered_set<T, H, P, A>::swap(unordered_set& other)
1273 // C++17 support: BOOST_NOEXCEPT_IF(
1274 // value_allocator_traits::is_always_equal::value &&
1275 // is_nothrow_move_assignable_v<H> &&
1276 // is_nothrow_move_assignable_v<P>)
1278 table_.swap(other.table_);
1283 template <class T, class H, class P, class A>
1284 typename unordered_set<T, H, P, A>::hasher
1285 unordered_set<T, H, P, A>::hash_function() const
1287 return table_.hash_function();
1290 template <class T, class H, class P, class A>
1291 typename unordered_set<T, H, P, A>::key_equal
1292 unordered_set<T, H, P, A>::key_eq() const
1294 return table_.key_eq();
1297 template <class T, class H, class P, class A>
1298 template <typename H2, typename P2>
1299 void unordered_set<T, H, P, A>::merge(
1300 boost::unordered_set<T, H2, P2, A>& source)
1302 table_.merge_unique(source.table_);
1305 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
1306 template <class T, class H, class P, class A>
1307 template <typename H2, typename P2>
1308 void unordered_set<T, H, P, A>::merge(
1309 boost::unordered_set<T, H2, P2, A>&& source)
1311 table_.merge_unique(source.table_);
1315 template <class T, class H, class P, class A>
1316 template <typename H2, typename P2>
1317 void unordered_set<T, H, P, A>::merge(
1318 boost::unordered_multiset<T, H2, P2, A>& source)
1320 table_.merge_unique(source.table_);
1323 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
1324 template <class T, class H, class P, class A>
1325 template <typename H2, typename P2>
1326 void unordered_set<T, H, P, A>::merge(
1327 boost::unordered_multiset<T, H2, P2, A>&& source)
1329 table_.merge_unique(source.table_);
1335 template <class T, class H, class P, class A>
1336 typename unordered_set<T, H, P, A>::const_iterator
1337 unordered_set<T, H, P, A>::find(const key_type& k) const
1339 return const_iterator(table_.find_node(k));
1342 template <class T, class H, class P, class A>
1343 template <class CompatibleKey, class CompatibleHash,
1344 class CompatiblePredicate>
1345 typename unordered_set<T, H, P, A>::const_iterator
1346 unordered_set<T, H, P, A>::find(CompatibleKey const& k,
1347 CompatibleHash const& hash, CompatiblePredicate const& eq) const
1349 return const_iterator(
1350 table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
1353 template <class T, class H, class P, class A>
1354 typename unordered_set<T, H, P, A>::size_type
1355 unordered_set<T, H, P, A>::count(const key_type& k) const
1357 return table_.find_node(k) ? 1 : 0;
1360 template <class T, class H, class P, class A>
1361 std::pair<typename unordered_set<T, H, P, A>::const_iterator,
1362 typename unordered_set<T, H, P, A>::const_iterator>
1363 unordered_set<T, H, P, A>::equal_range(const key_type& k) const
1365 node_pointer n = table_.find_node(k);
1366 return std::make_pair(
1367 const_iterator(n), const_iterator(n ? table::next_node(n) : n));
1370 template <class T, class H, class P, class A>
1371 typename unordered_set<T, H, P, A>::size_type
1372 unordered_set<T, H, P, A>::bucket_size(size_type n) const
1374 return table_.bucket_size(n);
1379 template <class T, class H, class P, class A>
1380 float unordered_set<T, H, P, A>::load_factor() const BOOST_NOEXCEPT
1382 BOOST_ASSERT(table_.bucket_count_ != 0);
1383 return static_cast<float>(table_.size_) /
1384 static_cast<float>(table_.bucket_count_);
1387 template <class T, class H, class P, class A>
1388 void unordered_set<T, H, P, A>::max_load_factor(float m) BOOST_NOEXCEPT
1390 table_.max_load_factor(m);
1393 template <class T, class H, class P, class A>
1394 void unordered_set<T, H, P, A>::rehash(size_type n)
1399 template <class T, class H, class P, class A>
1400 void unordered_set<T, H, P, A>::reserve(size_type n)
1402 table_.rehash(static_cast<std::size_t>(
1403 std::ceil(static_cast<double>(n) / table_.mlf_)));
1406 template <class T, class H, class P, class A>
1407 inline bool operator==(
1408 unordered_set<T, H, P, A> const& m1, unordered_set<T, H, P, A> const& m2)
1410 #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
1413 unordered_set<T, H, P, A> x;
1416 return m1.table_.equals_unique(m2.table_);
1419 template <class T, class H, class P, class A>
1420 inline bool operator!=(
1421 unordered_set<T, H, P, A> const& m1, unordered_set<T, H, P, A> const& m2)
1423 #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
1426 unordered_set<T, H, P, A> x;
1429 return !m1.table_.equals_unique(m2.table_);
1432 template <class T, class H, class P, class A>
1434 unordered_set<T, H, P, A>& m1, unordered_set<T, H, P, A>& m2)
1435 BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(m1.swap(m2)))
1437 #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
1440 unordered_set<T, H, P, A> x;
1446 ////////////////////////////////////////////////////////////////////////////
1448 template <class T, class H, class P, class A>
1449 unordered_multiset<T, H, P, A>::unordered_multiset()
1450 : table_(boost::unordered::detail::default_bucket_count, hasher(),
1451 key_equal(), allocator_type())
1455 template <class T, class H, class P, class A>
1456 unordered_multiset<T, H, P, A>::unordered_multiset(size_type n,
1457 const hasher& hf, const key_equal& eql, const allocator_type& a)
1458 : table_(n, hf, eql, a)
1462 template <class T, class H, class P, class A>
1463 template <class InputIt>
1464 unordered_multiset<T, H, P, A>::unordered_multiset(InputIt f, InputIt l,
1465 size_type n, const hasher& hf, const key_equal& eql,
1466 const allocator_type& a)
1467 : table_(boost::unordered::detail::initial_size(f, l, n), hf, eql, a)
1472 template <class T, class H, class P, class A>
1473 unordered_multiset<T, H, P, A>::unordered_multiset(
1474 unordered_multiset const& other)
1475 : table_(other.table_,
1476 unordered_multiset::value_allocator_traits::
1477 select_on_container_copy_construction(other.get_allocator()))
1479 if (other.table_.size_) {
1480 table_.copy_buckets(
1481 other.table_, boost::unordered::detail::false_type());
1485 template <class T, class H, class P, class A>
1486 unordered_multiset<T, H, P, A>::unordered_multiset(allocator_type const& a)
1487 : table_(boost::unordered::detail::default_bucket_count, hasher(),
1492 template <class T, class H, class P, class A>
1493 unordered_multiset<T, H, P, A>::unordered_multiset(
1494 unordered_multiset const& other, allocator_type const& a)
1495 : table_(other.table_, a)
1497 if (other.table_.size_) {
1498 table_.copy_buckets(
1499 other.table_, boost::unordered::detail::false_type());
1503 template <class T, class H, class P, class A>
1504 unordered_multiset<T, H, P, A>::unordered_multiset(
1505 BOOST_RV_REF(unordered_multiset) other, allocator_type const& a)
1506 : table_(other.table_, a, boost::unordered::detail::move_tag())
1508 table_.move_construct_buckets(other.table_);
1511 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1513 template <class T, class H, class P, class A>
1514 unordered_multiset<T, H, P, A>::unordered_multiset(
1515 std::initializer_list<value_type> list, size_type n, const hasher& hf,
1516 const key_equal& eql, const allocator_type& a)
1518 boost::unordered::detail::initial_size(list.begin(), list.end(), n),
1521 this->insert(list.begin(), list.end());
1526 template <class T, class H, class P, class A>
1527 unordered_multiset<T, H, P, A>::unordered_multiset(
1528 size_type n, const allocator_type& a)
1529 : table_(n, hasher(), key_equal(), a)
1533 template <class T, class H, class P, class A>
1534 unordered_multiset<T, H, P, A>::unordered_multiset(
1535 size_type n, const hasher& hf, const allocator_type& a)
1536 : table_(n, hf, key_equal(), a)
1540 template <class T, class H, class P, class A>
1541 template <class InputIt>
1542 unordered_multiset<T, H, P, A>::unordered_multiset(
1543 InputIt f, InputIt l, size_type n, const allocator_type& a)
1544 : table_(boost::unordered::detail::initial_size(f, l, n), hasher(),
1550 template <class T, class H, class P, class A>
1551 template <class InputIt>
1552 unordered_multiset<T, H, P, A>::unordered_multiset(InputIt f, InputIt l,
1553 size_type n, const hasher& hf, const allocator_type& a)
1555 boost::unordered::detail::initial_size(f, l, n), hf, key_equal(), a)
1560 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1562 template <class T, class H, class P, class A>
1563 unordered_multiset<T, H, P, A>::unordered_multiset(
1564 std::initializer_list<value_type> list, size_type n,
1565 const allocator_type& a)
1567 boost::unordered::detail::initial_size(list.begin(), list.end(), n),
1568 hasher(), key_equal(), a)
1570 this->insert(list.begin(), list.end());
1573 template <class T, class H, class P, class A>
1574 unordered_multiset<T, H, P, A>::unordered_multiset(
1575 std::initializer_list<value_type> list, size_type n, const hasher& hf,
1576 const allocator_type& a)
1578 boost::unordered::detail::initial_size(list.begin(), list.end(), n),
1581 this->insert(list.begin(), list.end());
1586 template <class T, class H, class P, class A>
1587 unordered_multiset<T, H, P, A>::~unordered_multiset() BOOST_NOEXCEPT
1591 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1593 template <class T, class H, class P, class A>
1594 unordered_multiset<T, H, P, A>& unordered_multiset<T, H, P, A>::operator=(
1595 std::initializer_list<value_type> list)
1598 this->insert(list.begin(), list.end());
1604 // size and capacity
1606 template <class T, class H, class P, class A>
1607 std::size_t unordered_multiset<T, H, P, A>::max_size() const BOOST_NOEXCEPT
1609 using namespace std;
1611 // size < mlf_ * count
1612 return boost::unordered::detail::double_to_size(
1613 ceil(static_cast<double>(table_.mlf_) *
1614 static_cast<double>(table_.max_bucket_count()))) -
1620 template <class T, class H, class P, class A>
1621 template <class InputIt>
1622 void unordered_multiset<T, H, P, A>::insert(InputIt first, InputIt last)
1624 table_.insert_range_equiv(first, last);
1627 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1628 template <class T, class H, class P, class A>
1629 void unordered_multiset<T, H, P, A>::insert(
1630 std::initializer_list<value_type> list)
1632 this->insert(list.begin(), list.end());
1636 template <class T, class H, class P, class A>
1637 typename unordered_multiset<T, H, P, A>::iterator
1638 unordered_multiset<T, H, P, A>::erase(const_iterator position)
1640 node_pointer node = table::get_node(position);
1642 node_pointer next = table::next_node(node);
1643 table_.erase_nodes_equiv(node, next);
1644 return iterator(next);
1647 template <class T, class H, class P, class A>
1648 typename unordered_multiset<T, H, P, A>::size_type
1649 unordered_multiset<T, H, P, A>::erase(const key_type& k)
1651 return table_.erase_key_equiv(k);
1654 template <class T, class H, class P, class A>
1655 typename unordered_multiset<T, H, P, A>::iterator
1656 unordered_multiset<T, H, P, A>::erase(
1657 const_iterator first, const_iterator last)
1659 node_pointer last_node = table::get_node(last);
1661 return iterator(last_node);
1662 table_.erase_nodes_equiv(table::get_node(first), last_node);
1663 return iterator(last_node);
1666 template <class T, class H, class P, class A>
1667 void unordered_multiset<T, H, P, A>::swap(unordered_multiset& other)
1668 // C++17 support: BOOST_NOEXCEPT_IF(
1669 // value_allocator_traits::is_always_equal::value &&
1670 // is_nothrow_move_assignable_v<H> &&
1671 // is_nothrow_move_assignable_v<P>)
1673 table_.swap(other.table_);
1678 template <class T, class H, class P, class A>
1679 typename unordered_multiset<T, H, P, A>::hasher
1680 unordered_multiset<T, H, P, A>::hash_function() const
1682 return table_.hash_function();
1685 template <class T, class H, class P, class A>
1686 typename unordered_multiset<T, H, P, A>::key_equal
1687 unordered_multiset<T, H, P, A>::key_eq() const
1689 return table_.key_eq();
1692 template <class T, class H, class P, class A>
1693 template <typename H2, typename P2>
1694 void unordered_multiset<T, H, P, A>::merge(
1695 boost::unordered_multiset<T, H2, P2, A>& source)
1697 while (!source.empty()) {
1698 insert(source.extract(source.begin()));
1702 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
1703 template <class T, class H, class P, class A>
1704 template <typename H2, typename P2>
1705 void unordered_multiset<T, H, P, A>::merge(
1706 boost::unordered_multiset<T, H2, P2, A>&& source)
1708 while (!source.empty()) {
1709 insert(source.extract(source.begin()));
1714 template <class T, class H, class P, class A>
1715 template <typename H2, typename P2>
1716 void unordered_multiset<T, H, P, A>::merge(
1717 boost::unordered_set<T, H2, P2, A>& source)
1719 while (!source.empty()) {
1720 insert(source.extract(source.begin()));
1724 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
1725 template <class T, class H, class P, class A>
1726 template <typename H2, typename P2>
1727 void unordered_multiset<T, H, P, A>::merge(
1728 boost::unordered_set<T, H2, P2, A>&& source)
1730 while (!source.empty()) {
1731 insert(source.extract(source.begin()));
1738 template <class T, class H, class P, class A>
1739 typename unordered_multiset<T, H, P, A>::const_iterator
1740 unordered_multiset<T, H, P, A>::find(const key_type& k) const
1742 return const_iterator(table_.find_node(k));
1745 template <class T, class H, class P, class A>
1746 template <class CompatibleKey, class CompatibleHash,
1747 class CompatiblePredicate>
1748 typename unordered_multiset<T, H, P, A>::const_iterator
1749 unordered_multiset<T, H, P, A>::find(CompatibleKey const& k,
1750 CompatibleHash const& hash, CompatiblePredicate const& eq) const
1752 return const_iterator(
1753 table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
1756 template <class T, class H, class P, class A>
1757 typename unordered_multiset<T, H, P, A>::size_type
1758 unordered_multiset<T, H, P, A>::count(const key_type& k) const
1760 node_pointer n = table_.find_node(k);
1761 return n ? table_.group_count(n) : 0;
1764 template <class T, class H, class P, class A>
1765 std::pair<typename unordered_multiset<T, H, P, A>::const_iterator,
1766 typename unordered_multiset<T, H, P, A>::const_iterator>
1767 unordered_multiset<T, H, P, A>::equal_range(const key_type& k) const
1769 node_pointer n = table_.find_node(k);
1770 return std::make_pair(
1771 const_iterator(n), const_iterator(n ? table_.next_group(n) : n));
1774 template <class T, class H, class P, class A>
1775 typename unordered_multiset<T, H, P, A>::size_type
1776 unordered_multiset<T, H, P, A>::bucket_size(size_type n) const
1778 return table_.bucket_size(n);
1783 template <class T, class H, class P, class A>
1784 float unordered_multiset<T, H, P, A>::load_factor() const BOOST_NOEXCEPT
1786 BOOST_ASSERT(table_.bucket_count_ != 0);
1787 return static_cast<float>(table_.size_) /
1788 static_cast<float>(table_.bucket_count_);
1791 template <class T, class H, class P, class A>
1792 void unordered_multiset<T, H, P, A>::max_load_factor(float m) BOOST_NOEXCEPT
1794 table_.max_load_factor(m);
1797 template <class T, class H, class P, class A>
1798 void unordered_multiset<T, H, P, A>::rehash(size_type n)
1803 template <class T, class H, class P, class A>
1804 void unordered_multiset<T, H, P, A>::reserve(size_type n)
1806 table_.rehash(static_cast<std::size_t>(
1807 std::ceil(static_cast<double>(n) / table_.mlf_)));
1810 template <class T, class H, class P, class A>
1811 inline bool operator==(unordered_multiset<T, H, P, A> const& m1,
1812 unordered_multiset<T, H, P, A> const& m2)
1814 #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
1817 unordered_multiset<T, H, P, A> x;
1820 return m1.table_.equals_equiv(m2.table_);
1823 template <class T, class H, class P, class A>
1824 inline bool operator!=(unordered_multiset<T, H, P, A> const& m1,
1825 unordered_multiset<T, H, P, A> const& m2)
1827 #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
1830 unordered_multiset<T, H, P, A> x;
1833 return !m1.table_.equals_equiv(m2.table_);
1836 template <class T, class H, class P, class A>
1838 unordered_multiset<T, H, P, A>& m1, unordered_multiset<T, H, P, A>& m2)
1839 BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(m1.swap(m2)))
1841 #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
1844 unordered_multiset<T, H, P, A> x;
1850 template <typename N, typename T, typename A> class node_handle_set
1852 BOOST_MOVABLE_BUT_NOT_COPYABLE(node_handle_set)
1854 template <typename Types> friend struct ::boost::unordered::detail::table;
1855 template <class T2, class H2, class P2, class A2>
1856 friend class unordered_set;
1857 template <class T2, class H2, class P2, class A2>
1858 friend class unordered_multiset;
1860 typedef typename boost::unordered::detail::rebind_wrap<A, T>::type
1862 typedef boost::unordered::detail::allocator_traits<value_allocator>
1863 value_allocator_traits;
1865 typedef typename boost::unordered::detail::rebind_wrap<A, node>::type
1867 typedef boost::unordered::detail::allocator_traits<node_allocator>
1868 node_allocator_traits;
1869 typedef typename node_allocator_traits::pointer node_pointer;
1872 typedef T value_type;
1873 typedef A allocator_type;
1878 boost::unordered::detail::value_base<value_allocator> alloc_;
1880 node_handle_set(node_pointer ptr, allocator_type const& a)
1881 : ptr_(ptr), has_alloc_(false)
1884 new ((void*)&alloc_) value_allocator(a);
1890 BOOST_CONSTEXPR node_handle_set() BOOST_NOEXCEPT : ptr_(),
1897 if (has_alloc_ && ptr_) {
1898 node_allocator node_alloc(alloc_.value());
1899 boost::unordered::detail::node_tmp<node_allocator> tmp(
1903 alloc_.value_ptr()->~value_allocator();
1907 node_handle_set(BOOST_RV_REF(node_handle_set) n) BOOST_NOEXCEPT
1912 new ((void*)&alloc_) value_allocator(boost::move(n.alloc_.value()));
1914 n.ptr_ = node_pointer();
1915 n.alloc_.value_ptr()->~value_allocator();
1916 n.has_alloc_ = false;
1920 node_handle_set& operator=(BOOST_RV_REF(node_handle_set) n)
1922 BOOST_ASSERT(!has_alloc_ ||
1923 value_allocator_traits::
1924 propagate_on_container_move_assignment::value ||
1925 (n.has_alloc_ && alloc_.value() == n.alloc_.value()));
1928 node_allocator node_alloc(alloc_.value());
1929 boost::unordered::detail::node_tmp<node_allocator> tmp(
1931 ptr_ = node_pointer();
1935 alloc_.value_ptr()->~value_allocator();
1939 if (!has_alloc_ && n.has_alloc_) {
1944 n.ptr_ = node_pointer();
1949 value_type& value() const { return ptr_->value(); }
1951 allocator_type get_allocator() const { return alloc_.value(); }
1953 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
1955 bool operator!() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; }
1957 bool empty() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; }
1959 void swap(node_handle_set& n) BOOST_NOEXCEPT_IF(
1960 value_allocator_traits::propagate_on_container_swap::value
1961 /* || value_allocator_traits::is_always_equal::value */)
1967 } else if (!n.has_alloc_) {
1968 n.move_allocator(*this);
1971 n, boost::unordered::detail::integral_constant<bool,
1972 value_allocator_traits::propagate_on_container_swap::value>());
1974 boost::swap(ptr_, n.ptr_);
1978 void move_allocator(node_handle_set& n)
1980 new ((void*)&alloc_) value_allocator(boost::move(n.alloc_.value()));
1981 n.alloc_.value_ptr()->~value_allocator();
1983 n.has_alloc_ = false;
1986 void swap_impl(node_handle_set&, boost::unordered::detail::false_type) {}
1988 void swap_impl(node_handle_set& n, boost::unordered::detail::true_type)
1990 boost::swap(alloc_, n.alloc_);
1994 template <typename N, typename T, typename A>
1995 void swap(node_handle_set<N, T, A>& x, node_handle_set<N, T, A>& y)
1996 BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(x.swap(y)))
2001 template <typename N, typename T, typename A> struct insert_return_type_set
2004 BOOST_MOVABLE_BUT_NOT_COPYABLE(insert_return_type_set)
2006 typedef typename boost::unordered::detail::rebind_wrap<A, T>::type
2012 boost::unordered::iterator_detail::c_iterator<node_> position;
2013 boost::unordered::node_handle_set<N, T, A> node;
2015 insert_return_type_set() : inserted(false), position(), node() {}
2017 insert_return_type_set(BOOST_RV_REF(insert_return_type_set)
2018 x) BOOST_NOEXCEPT : inserted(x.inserted),
2019 position(x.position),
2020 node(boost::move(x.node))
2024 insert_return_type_set& operator=(BOOST_RV_REF(insert_return_type_set) x)
2026 inserted = x.inserted;
2027 position = x.position;
2028 node = boost::move(x.node);
2033 template <typename N, typename T, typename A>
2035 insert_return_type_set<N, T, A>& x, insert_return_type_set<N, T, A>& y)
2037 boost::swap(x.node, y.node);
2038 boost::swap(x.inserted, y.inserted);
2039 boost::swap(x.position, y.position);
2041 } // namespace unordered
2042 } // namespace boost
2044 #if defined(BOOST_MSVC)
2045 #pragma warning(pop)
2048 #endif // BOOST_UNORDERED_UNORDERED_SET_HPP_INCLUDED