123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428 |
- //////////////////////////////////////////////////////////////////////////////
- //
- // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
- // Software License, Version 1.0. (See accompanying file
- // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- // See http://www.boost.org/libs/container for documentation.
- //
- //////////////////////////////////////////////////////////////////////////////
- #ifndef BOOST_CONTAINER_FLAT_SET_HPP
- #define BOOST_CONTAINER_FLAT_SET_HPP
- #if defined(_MSC_VER)
- # pragma once
- #endif
- #include <boost/container/detail/config_begin.hpp>
- #include <boost/container/detail/workaround.hpp>
- #include <boost/container/container_fwd.hpp>
- #include <utility>
- #include <functional>
- #include <memory>
- #include <boost/container/detail/flat_tree.hpp>
- #include <boost/container/detail/mpl.hpp>
- #include <boost/container/allocator_traits.hpp>
- #include <boost/move/utility.hpp>
- #include <boost/move/detail/move_helpers.hpp>
- namespace boost {
- namespace container {
- /// @cond
- // Forward declarations of operators < and ==, needed for friend declaration.
- #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> >
- #else
- template <class Key, class Compare, class Allocator>
- #endif
- class flat_set;
- template <class Key, class Compare, class Allocator>
- inline bool operator==(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y);
- template <class Key, class Compare, class Allocator>
- inline bool operator<(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y);
- /// @endcond
- //! flat_set is a Sorted Associative Container that stores objects of type Key.
- //! It is also a Unique Associative Container, meaning that no two elements are the same.
- //!
- //! flat_set is similar to std::set but it's implemented like an ordered vector.
- //! This means that inserting a new element into a flat_set invalidates
- //! previous iterators and references
- //!
- //! Erasing an element of a flat_set invalidates iterators and references
- //! pointing to elements that come after (their keys are bigger) the erased element.
- //!
- //! This container provides random-access iterators.
- #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> >
- #else
- template <class Key, class Compare, class Allocator>
- #endif
- class flat_set
- {
- /// @cond
- private:
- BOOST_COPYABLE_AND_MOVABLE(flat_set)
- typedef container_detail::flat_tree<Key, Key, container_detail::identity<Key>, Compare, Allocator> tree_t;
- tree_t m_flat_tree; // flat tree representing flat_set
- /// @endcond
- public:
- //////////////////////////////////////////////
- //
- // types
- //
- //////////////////////////////////////////////
- typedef Key key_type;
- typedef Key value_type;
- typedef Compare key_compare;
- typedef Compare value_compare;
- typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
- typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
- typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
- typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
- typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
- typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
- typedef Allocator allocator_type;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type) stored_allocator_type;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::iterator) iterator;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::const_iterator) const_iterator;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::reverse_iterator) reverse_iterator;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::const_reverse_iterator) const_reverse_iterator;
- public:
- //////////////////////////////////////////////
- //
- // construct/copy/destroy
- //
- //////////////////////////////////////////////
- //! <b>Effects</b>: Default constructs an empty flat_set.
- //!
- //! <b>Complexity</b>: Constant.
- explicit flat_set()
- : m_flat_tree()
- {}
- //! <b>Effects</b>: Constructs an empty flat_set using the specified
- //! comparison object and allocator.
- //!
- //! <b>Complexity</b>: Constant.
- explicit flat_set(const Compare& comp,
- const allocator_type& a = allocator_type())
- : m_flat_tree(comp, a)
- {}
- //! <b>Effects</b>: Constructs an empty flat_set using the specified allocator.
- //!
- //! <b>Complexity</b>: Constant.
- explicit flat_set(const allocator_type& a)
- : m_flat_tree(a)
- {}
- //! <b>Effects</b>: Constructs an empty set using the specified comparison object and
- //! allocator, and inserts elements from the range [first ,last ).
- //!
- //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
- //! comp and otherwise N logN, where N is last - first.
- template <class InputIterator>
- flat_set(InputIterator first, InputIterator last,
- const Compare& comp = Compare(),
- const allocator_type& a = allocator_type())
- : m_flat_tree(true, first, last, comp, a)
- {}
- //! <b>Effects</b>: Constructs an empty flat_set using the specified comparison object and
- //! allocator, and inserts elements from the ordered unique range [first ,last). This function
- //! is more efficient than the normal range creation for ordered ranges.
- //!
- //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
- //! unique values.
- //!
- //! <b>Complexity</b>: Linear in N.
- //!
- //! <b>Note</b>: Non-standard extension.
- template <class InputIterator>
- flat_set(ordered_unique_range_t, InputIterator first, InputIterator last,
- const Compare& comp = Compare(),
- const allocator_type& a = allocator_type())
- : m_flat_tree(ordered_range, first, last, comp, a)
- {}
- //! <b>Effects</b>: Copy constructs a set.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_set(const flat_set& x)
- : m_flat_tree(x.m_flat_tree)
- {}
- //! <b>Effects</b>: Move constructs a set. Constructs *this using x's resources.
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Postcondition</b>: x is emptied.
- flat_set(BOOST_RV_REF(flat_set) mx)
- : m_flat_tree(boost::move(mx.m_flat_tree))
- {}
- //! <b>Effects</b>: Copy constructs a set using the specified allocator.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_set(const flat_set& x, const allocator_type &a)
- : m_flat_tree(x.m_flat_tree, a)
- {}
- //! <b>Effects</b>: Move constructs a set using the specified allocator.
- //! Constructs *this using x's resources.
- //!
- //! <b>Complexity</b>: Constant if a == mx.get_allocator(), linear otherwise
- flat_set(BOOST_RV_REF(flat_set) mx, const allocator_type &a)
- : m_flat_tree(boost::move(mx.m_flat_tree), a)
- {}
- //! <b>Effects</b>: Makes *this a copy of x.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_set& operator=(BOOST_COPY_ASSIGN_REF(flat_set) x)
- { m_flat_tree = x.m_flat_tree; return *this; }
- //! <b>Effects</b>: Makes *this a copy of the previous value of xx.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_set& operator=(BOOST_RV_REF(flat_set) mx)
- { m_flat_tree = boost::move(mx.m_flat_tree); return *this; }
- //! <b>Effects</b>: Returns a copy of the Allocator that
- //! was passed to the object's constructor.
- //!
- //! <b>Complexity</b>: Constant.
- allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.get_allocator(); }
- //! <b>Effects</b>: Returns a reference to the internal allocator.
- //!
- //! <b>Throws</b>: Nothing
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Note</b>: Non-standard extension.
- stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.get_stored_allocator(); }
- //! <b>Effects</b>: Returns a reference to the internal allocator.
- //!
- //! <b>Throws</b>: Nothing
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Note</b>: Non-standard extension.
- const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.get_stored_allocator(); }
- //////////////////////////////////////////////
- //
- // iterators
- //
- //////////////////////////////////////////////
- //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- iterator begin() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.begin(); }
- //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator begin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.begin(); }
- //! <b>Effects</b>: Returns an iterator to the end of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- iterator end() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.end(); }
- //! <b>Effects</b>: Returns a const_iterator to the end of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator end() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.end(); }
- //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rbegin(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rbegin(); }
- //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rend(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rend(); }
- //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.cbegin(); }
- //! <b>Effects</b>: Returns a const_iterator to the end of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator cend() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.cend(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.crbegin(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.crend(); }
- //////////////////////////////////////////////
- //
- // capacity
- //
- //////////////////////////////////////////////
- //! <b>Effects</b>: Returns true if the container contains no elements.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- bool empty() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.empty(); }
- //! <b>Effects</b>: Returns the number of the elements contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type size() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.size(); }
- //! <b>Effects</b>: Returns the largest possible size of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type max_size() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.max_size(); }
- //! <b>Effects</b>: Number of elements for which memory has been allocated.
- //! capacity() is always greater than or equal to size().
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type capacity() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.capacity(); }
- //! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
- //! effect. Otherwise, it is a request for allocation of additional memory.
- //! If the request is successful, then capacity() is greater than or equal to
- //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
- //!
- //! <b>Throws</b>: If memory allocation allocation throws or Key's copy constructor throws.
- //!
- //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
- //! to values might be invalidated.
- void reserve(size_type cnt)
- { m_flat_tree.reserve(cnt); }
- //! <b>Effects</b>: Tries to deallocate the excess of memory created
- // with previous allocations. The size of the vector is unchanged
- //!
- //! <b>Throws</b>: If memory allocation throws, or Key's copy constructor throws.
- //!
- //! <b>Complexity</b>: Linear to size().
- void shrink_to_fit()
- { m_flat_tree.shrink_to_fit(); }
- //////////////////////////////////////////////
- //
- // modifiers
- //
- //////////////////////////////////////////////
- #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts an object x of type Key constructed with
- //! std::forward<Args>(args)... if and only if there is no element in the container
- //! with key equivalent to the key of x.
- //!
- //! <b>Returns</b>: The bool component of the returned pair is true if and only
- //! if the insertion takes place, and the iterator component of the pair
- //! points to the element with key equivalent to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus linear insertion
- //! to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- template <class... Args>
- std::pair<iterator,bool> emplace(Args&&... args)
- { return m_flat_tree.emplace_unique(boost::forward<Args>(args)...); }
- //! <b>Effects</b>: Inserts an object of type Key constructed with
- //! std::forward<Args>(args)... in the container if and only if there is
- //! no element in the container with key equivalent to the key of x.
- //! p is a hint pointing to where the insert should start to search.
- //!
- //! <b>Returns</b>: An iterator pointing to the element with key equivalent
- //! to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
- //! right before p) plus insertion linear to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- template <class... Args>
- iterator emplace_hint(const_iterator hint, Args&&... args)
- { return m_flat_tree.emplace_hint_unique(hint, boost::forward<Args>(args)...); }
- #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
- #define BOOST_PP_LOCAL_MACRO(n) \
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
- std::pair<iterator,bool> emplace(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- { return m_flat_tree.emplace_unique(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); } \
- \
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
- iterator emplace_hint(const_iterator hint \
- BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- { return m_flat_tree.emplace_hint_unique \
- (hint BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); } \
- //!
- #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
- #include BOOST_PP_LOCAL_ITERATE()
- #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts x if and only if there is no element in the container
- //! with key equivalent to the key of x.
- //!
- //! <b>Returns</b>: The bool component of the returned pair is true if and only
- //! if the insertion takes place, and the iterator component of the pair
- //! points to the element with key equivalent to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus linear insertion
- //! to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- std::pair<iterator, bool> insert(const value_type &x);
- //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
- //! only if there is no element in the container with key equivalent to the key of x.
- //!
- //! <b>Returns</b>: The bool component of the returned pair is true if and only
- //! if the insertion takes place, and the iterator component of the pair
- //! points to the element with key equivalent to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus linear insertion
- //! to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- std::pair<iterator, bool> insert(value_type &&x);
- #else
- private:
- typedef std::pair<iterator, bool> insert_return_pair;
- public:
- BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, insert_return_pair, this->priv_insert)
- #endif
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
- //! no element in the container with key equivalent to the key of x.
- //! p is a hint pointing to where the insert should start to search.
- //!
- //! <b>Returns</b>: An iterator pointing to the element with key equivalent
- //! to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
- //! right before p) plus insertion linear to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- iterator insert(const_iterator p, const value_type &x);
- //! <b>Effects</b>: Inserts an element move constructed from x in the container.
- //! p is a hint pointing to where the insert should start to search.
- //!
- //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
- //! right before p) plus insertion linear to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- iterator insert(const_iterator position, value_type &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator)
- #endif
- //! <b>Requires</b>: first, last are not iterators into *this.
- //!
- //! <b>Effects</b>: inserts each element from the range [first,last) if and only
- //! if there is no element with key equivalent to the key of that element.
- //!
- //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
- //! search time plus N*size() insertion time.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- template <class InputIterator>
- void insert(InputIterator first, InputIterator last)
- { m_flat_tree.insert_unique(first, last); }
- //! <b>Requires</b>: first, last are not iterators into *this and
- //! must be ordered according to the predicate and must be
- //! unique values.
- //!
- //! <b>Effects</b>: inserts each element from the range [first,last) .This function
- //! is more efficient than the normal range creation for ordered ranges.
- //!
- //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
- //! search time plus N*size() insertion time.
- //!
- //! <b>Note</b>: Non-standard extension. If an element is inserted it might invalidate elements.
- template <class InputIterator>
- void insert(ordered_unique_range_t, InputIterator first, InputIterator last)
- { m_flat_tree.insert_unique(ordered_unique_range, first, last); }
- //! <b>Effects</b>: Erases the element pointed to by position.
- //!
- //! <b>Returns</b>: Returns an iterator pointing to the element immediately
- //! following q prior to the element being erased. If no such element exists,
- //! returns end().
- //!
- //! <b>Complexity</b>: Linear to the elements with keys bigger than position
- //!
- //! <b>Note</b>: Invalidates elements with keys
- //! not less than the erased element.
- iterator erase(const_iterator position)
- { return m_flat_tree.erase(position); }
- //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
- //!
- //! <b>Returns</b>: Returns the number of erased elements.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus erasure time
- //! linear to the elements with bigger keys.
- size_type erase(const key_type& x)
- { return m_flat_tree.erase(x); }
- //! <b>Effects</b>: Erases all the elements in the range [first, last).
- //!
- //! <b>Returns</b>: Returns last.
- //!
- //! <b>Complexity</b>: size()*N where N is the distance from first to last.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus erasure time
- //! linear to the elements with bigger keys.
- iterator erase(const_iterator first, const_iterator last)
- { return m_flat_tree.erase(first, last); }
- //! <b>Effects</b>: Swaps the contents of *this and x.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- void swap(flat_set& x)
- { m_flat_tree.swap(x.m_flat_tree); }
- //! <b>Effects</b>: erase(a.begin(),a.end()).
- //!
- //! <b>Postcondition</b>: size() == 0.
- //!
- //! <b>Complexity</b>: linear in size().
- void clear() BOOST_CONTAINER_NOEXCEPT
- { m_flat_tree.clear(); }
- //////////////////////////////////////////////
- //
- // observers
- //
- //////////////////////////////////////////////
- //! <b>Effects</b>: Returns the comparison object out
- //! of which a was constructed.
- //!
- //! <b>Complexity</b>: Constant.
- key_compare key_comp() const
- { return m_flat_tree.key_comp(); }
- //! <b>Effects</b>: Returns an object of value_compare constructed out
- //! of the comparison object.
- //!
- //! <b>Complexity</b>: Constant.
- value_compare value_comp() const
- { return m_flat_tree.key_comp(); }
- //////////////////////////////////////////////
- //
- // set operations
- //
- //////////////////////////////////////////////
- //! <b>Returns</b>: An iterator pointing to an element with the key
- //! equivalent to x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic.
- iterator find(const key_type& x)
- { return m_flat_tree.find(x); }
- //! <b>Returns</b>: Allocator const_iterator pointing to an element with the key
- //! equivalent to x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic.s
- const_iterator find(const key_type& x) const
- { return m_flat_tree.find(x); }
- //! <b>Returns</b>: The number of elements with key equivalent to x.
- //!
- //! <b>Complexity</b>: log(size())+count(k)
- size_type count(const key_type& x) const
- { return static_cast<size_type>(m_flat_tree.find(x) != m_flat_tree.end()); }
- //! <b>Returns</b>: An iterator pointing to the first element with key not less
- //! than k, or a.end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- iterator lower_bound(const key_type& x)
- { return m_flat_tree.lower_bound(x); }
- //! <b>Returns</b>: Allocator const iterator pointing to the first element with key not
- //! less than k, or a.end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- const_iterator lower_bound(const key_type& x) const
- { return m_flat_tree.lower_bound(x); }
- //! <b>Returns</b>: An iterator pointing to the first element with key not less
- //! than x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- iterator upper_bound(const key_type& x)
- { return m_flat_tree.upper_bound(x); }
- //! <b>Returns</b>: Allocator const iterator pointing to the first element with key not
- //! less than x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- const_iterator upper_bound(const key_type& x) const
- { return m_flat_tree.upper_bound(x); }
- //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
- //!
- //! <b>Complexity</b>: Logarithmic
- std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
- { return m_flat_tree.equal_range(x); }
- //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
- //!
- //! <b>Complexity</b>: Logarithmic
- std::pair<iterator,iterator> equal_range(const key_type& x)
- { return m_flat_tree.equal_range(x); }
- /// @cond
- template <class K1, class C1, class A1>
- friend bool operator== (const flat_set<K1,C1,A1>&, const flat_set<K1,C1,A1>&);
- template <class K1, class C1, class A1>
- friend bool operator< (const flat_set<K1,C1,A1>&, const flat_set<K1,C1,A1>&);
- private:
- template<class KeyType>
- std::pair<iterator, bool> priv_insert(BOOST_FWD_REF(KeyType) x)
- { return m_flat_tree.insert_unique(::boost::forward<KeyType>(x)); }
- template<class KeyType>
- iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x)
- { return m_flat_tree.insert_unique(p, ::boost::forward<KeyType>(x)); }
- /// @endcond
- };
- template <class Key, class Compare, class Allocator>
- inline bool operator==(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y)
- { return x.m_flat_tree == y.m_flat_tree; }
- template <class Key, class Compare, class Allocator>
- inline bool operator<(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y)
- { return x.m_flat_tree < y.m_flat_tree; }
- template <class Key, class Compare, class Allocator>
- inline bool operator!=(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y)
- { return !(x == y); }
- template <class Key, class Compare, class Allocator>
- inline bool operator>(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y)
- { return y < x; }
- template <class Key, class Compare, class Allocator>
- inline bool operator<=(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y)
- { return !(y < x); }
- template <class Key, class Compare, class Allocator>
- inline bool operator>=(const flat_set<Key,Compare,Allocator>& x,
- const flat_set<Key,Compare,Allocator>& y)
- { return !(x < y); }
- template <class Key, class Compare, class Allocator>
- inline void swap(flat_set<Key,Compare,Allocator>& x, flat_set<Key,Compare,Allocator>& y)
- { x.swap(y); }
- /// @cond
- } //namespace container {
- //!has_trivial_destructor_after_move<> == true_type
- //!specialization for optimizations
- template <class Key, class C, class Allocator>
- struct has_trivial_destructor_after_move<boost::container::flat_set<Key, C, Allocator> >
- {
- static const bool value = has_trivial_destructor_after_move<Allocator>::value &&has_trivial_destructor_after_move<C>::value;
- };
- namespace container {
- // Forward declaration of operators < and ==, needed for friend declaration.
- #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> >
- #else
- template <class Key, class Compare, class Allocator>
- #endif
- class flat_multiset;
- template <class Key, class Compare, class Allocator>
- inline bool operator==(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y);
- template <class Key, class Compare, class Allocator>
- inline bool operator<(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y);
- /// @endcond
- //! flat_multiset is a Sorted Associative Container that stores objects of type Key.
- //!
- //! flat_multiset can store multiple copies of the same key value.
- //!
- //! flat_multiset is similar to std::multiset but it's implemented like an ordered vector.
- //! This means that inserting a new element into a flat_multiset invalidates
- //! previous iterators and references
- //!
- //! Erasing an element invalidates iterators and references
- //! pointing to elements that come after (their keys are bigger) the erased element.
- //!
- //! This container provides random-access iterators.
- #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> >
- #else
- template <class Key, class Compare, class Allocator>
- #endif
- class flat_multiset
- {
- /// @cond
- private:
- BOOST_COPYABLE_AND_MOVABLE(flat_multiset)
- typedef container_detail::flat_tree<Key, Key, container_detail::identity<Key>, Compare, Allocator> tree_t;
- tree_t m_flat_tree; // flat tree representing flat_multiset
- /// @endcond
- public:
- //////////////////////////////////////////////
- //
- // types
- //
- //////////////////////////////////////////////
- typedef Key key_type;
- typedef Key value_type;
- typedef Compare key_compare;
- typedef Compare value_compare;
- typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
- typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
- typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
- typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
- typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
- typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
- typedef Allocator allocator_type;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type) stored_allocator_type;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::iterator) iterator;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::const_iterator) const_iterator;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::reverse_iterator) reverse_iterator;
- typedef typename BOOST_CONTAINER_IMPDEF(tree_t::const_reverse_iterator) const_reverse_iterator;
- //! <b>Effects</b>: Default constructs an empty flat_multiset.
- //!
- //! <b>Complexity</b>: Constant.
- explicit flat_multiset()
- : m_flat_tree()
- {}
- //! <b>Effects</b>: Constructs an empty flat_multiset using the specified
- //! comparison object and allocator.
- //!
- //! <b>Complexity</b>: Constant.
- explicit flat_multiset(const Compare& comp,
- const allocator_type& a = allocator_type())
- : m_flat_tree(comp, a)
- {}
- //! <b>Effects</b>: Constructs an empty flat_multiset using the specified allocator.
- //!
- //! <b>Complexity</b>: Constant.
- explicit flat_multiset(const allocator_type& a)
- : m_flat_tree(a)
- {}
- template <class InputIterator>
- flat_multiset(InputIterator first, InputIterator last,
- const Compare& comp = Compare(),
- const allocator_type& a = allocator_type())
- : m_flat_tree(false, first, last, comp, a)
- {}
- //! <b>Effects</b>: Constructs an empty flat_multiset using the specified comparison object and
- //! allocator, and inserts elements from the ordered range [first ,last ). This function
- //! is more efficient than the normal range creation for ordered ranges.
- //!
- //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
- //!
- //! <b>Complexity</b>: Linear in N.
- //!
- //! <b>Note</b>: Non-standard extension.
- template <class InputIterator>
- flat_multiset(ordered_range_t, InputIterator first, InputIterator last,
- const Compare& comp = Compare(),
- const allocator_type& a = allocator_type())
- : m_flat_tree(ordered_range, first, last, comp, a)
- {}
- //! <b>Effects</b>: Copy constructs a flat_multiset.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_multiset(const flat_multiset& x)
- : m_flat_tree(x.m_flat_tree)
- {}
- //! <b>Effects</b>: Move constructs a flat_multiset. Constructs *this using x's resources.
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Postcondition</b>: x is emptied.
- flat_multiset(BOOST_RV_REF(flat_multiset) mx)
- : m_flat_tree(boost::move(mx.m_flat_tree))
- {}
- //! <b>Effects</b>: Copy constructs a flat_multiset using the specified allocator.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_multiset(const flat_multiset& x, const allocator_type &a)
- : m_flat_tree(x.m_flat_tree, a)
- {}
- //! <b>Effects</b>: Move constructs a flat_multiset using the specified allocator.
- //! Constructs *this using x's resources.
- //!
- //! <b>Complexity</b>: Constant if a == mx.get_allocator(), linear otherwise
- flat_multiset(BOOST_RV_REF(flat_multiset) mx, const allocator_type &a)
- : m_flat_tree(boost::move(mx.m_flat_tree), a)
- {}
- //! <b>Effects</b>: Makes *this a copy of x.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_multiset& operator=(BOOST_COPY_ASSIGN_REF(flat_multiset) x)
- { m_flat_tree = x.m_flat_tree; return *this; }
- //! <b>Effects</b>: Makes *this a copy of x.
- //!
- //! <b>Complexity</b>: Linear in x.size().
- flat_multiset& operator=(BOOST_RV_REF(flat_multiset) mx)
- { m_flat_tree = boost::move(mx.m_flat_tree); return *this; }
- //! <b>Effects</b>: Returns a copy of the Allocator that
- //! was passed to the object's constructor.
- //!
- //! <b>Complexity</b>: Constant.
- allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.get_allocator(); }
- //! <b>Effects</b>: Returns a reference to the internal allocator.
- //!
- //! <b>Throws</b>: Nothing
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Note</b>: Non-standard extension.
- stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.get_stored_allocator(); }
- //! <b>Effects</b>: Returns a reference to the internal allocator.
- //!
- //! <b>Throws</b>: Nothing
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Note</b>: Non-standard extension.
- const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.get_stored_allocator(); }
- //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- iterator begin() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.begin(); }
- //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator begin() const
- { return m_flat_tree.begin(); }
- //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.cbegin(); }
- //! <b>Effects</b>: Returns an iterator to the end of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- iterator end() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.end(); }
- //! <b>Effects</b>: Returns a const_iterator to the end of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator end() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.end(); }
- //! <b>Effects</b>: Returns a const_iterator to the end of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator cend() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.cend(); }
- //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rbegin(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rbegin(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.crbegin(); }
- //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rend(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.rend(); }
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
- //! of the reversed container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.crend(); }
- //////////////////////////////////////////////
- //
- // capacity
- //
- //////////////////////////////////////////////
- //! <b>Effects</b>: Returns true if the container contains no elements.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- bool empty() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.empty(); }
- //! <b>Effects</b>: Returns the number of the elements contained in the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type size() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.size(); }
- //! <b>Effects</b>: Returns the largest possible size of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type max_size() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.max_size(); }
- //! <b>Effects</b>: Number of elements for which memory has been allocated.
- //! capacity() is always greater than or equal to size().
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type capacity() const BOOST_CONTAINER_NOEXCEPT
- { return m_flat_tree.capacity(); }
- //! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
- //! effect. Otherwise, it is a request for allocation of additional memory.
- //! If the request is successful, then capacity() is greater than or equal to
- //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
- //!
- //! <b>Throws</b>: If memory allocation allocation throws or Key's copy constructor throws.
- //!
- //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
- //! to values might be invalidated.
- void reserve(size_type cnt)
- { m_flat_tree.reserve(cnt); }
- //! <b>Effects</b>: Tries to deallocate the excess of memory created
- // with previous allocations. The size of the vector is unchanged
- //!
- //! <b>Throws</b>: If memory allocation throws, or Key's copy constructor throws.
- //!
- //! <b>Complexity</b>: Linear to size().
- void shrink_to_fit()
- { m_flat_tree.shrink_to_fit(); }
- //////////////////////////////////////////////
- //
- // modifiers
- //
- //////////////////////////////////////////////
- #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts an object of type Key constructed with
- //! std::forward<Args>(args)... and returns the iterator pointing to the
- //! newly inserted element.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus linear insertion
- //! to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- template <class... Args>
- iterator emplace(Args&&... args)
- { return m_flat_tree.emplace_equal(boost::forward<Args>(args)...); }
- //! <b>Effects</b>: Inserts an object of type Key constructed with
- //! std::forward<Args>(args)... in the container.
- //! p is a hint pointing to where the insert should start to search.
- //!
- //! <b>Returns</b>: An iterator pointing to the element with key equivalent
- //! to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
- //! right before p) plus insertion linear to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- template <class... Args>
- iterator emplace_hint(const_iterator hint, Args&&... args)
- { return m_flat_tree.emplace_hint_equal(hint, boost::forward<Args>(args)...); }
- #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
- #define BOOST_PP_LOCAL_MACRO(n) \
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
- iterator emplace(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- { return m_flat_tree.emplace_equal(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); } \
- \
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
- iterator emplace_hint(const_iterator hint \
- BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- { return m_flat_tree.emplace_hint_equal \
- (hint BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); } \
- //!
- #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
- #include BOOST_PP_LOCAL_ITERATE()
- #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
- //! newly inserted element.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus linear insertion
- //! to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- iterator insert(const value_type &x);
- //! <b>Effects</b>: Inserts a new value_type move constructed from x
- //! and returns the iterator pointing to the newly inserted element.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus linear insertion
- //! to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- iterator insert(value_type &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, iterator, this->priv_insert)
- #endif
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts a copy of x in the container.
- //! p is a hint pointing to where the insert should start to search.
- //!
- //! <b>Returns</b>: An iterator pointing to the element with key equivalent
- //! to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
- //! right before p) plus insertion linear to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- iterator insert(const_iterator p, const value_type &x);
- //! <b>Effects</b>: Inserts a new value move constructed from x in the container.
- //! p is a hint pointing to where the insert should start to search.
- //!
- //! <b>Returns</b>: An iterator pointing to the element with key equivalent
- //! to the key of x.
- //!
- //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
- //! right before p) plus insertion linear to the elements with bigger keys than x.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- iterator insert(const_iterator position, value_type &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator)
- #endif
- //! <b>Requires</b>: first, last are not iterators into *this.
- //!
- //! <b>Effects</b>: inserts each element from the range [first,last) .
- //!
- //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
- //! search time plus N*size() insertion time.
- //!
- //! <b>Note</b>: If an element is inserted it might invalidate elements.
- template <class InputIterator>
- void insert(InputIterator first, InputIterator last)
- { m_flat_tree.insert_equal(first, last); }
- //! <b>Requires</b>: first, last are not iterators into *this and
- //! must be ordered according to the predicate.
- //!
- //! <b>Effects</b>: inserts each element from the range [first,last) .This function
- //! is more efficient than the normal range creation for ordered ranges.
- //!
- //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
- //! search time plus N*size() insertion time.
- //!
- //! <b>Note</b>: Non-standard extension. If an element is inserted it might invalidate elements.
- template <class InputIterator>
- void insert(ordered_range_t, InputIterator first, InputIterator last)
- { m_flat_tree.insert_equal(ordered_range, first, last); }
- //! <b>Effects</b>: Erases the element pointed to by position.
- //!
- //! <b>Returns</b>: Returns an iterator pointing to the element immediately
- //! following q prior to the element being erased. If no such element exists,
- //! returns end().
- //!
- //! <b>Complexity</b>: Linear to the elements with keys bigger than position
- //!
- //! <b>Note</b>: Invalidates elements with keys
- //! not less than the erased element.
- iterator erase(const_iterator position)
- { return m_flat_tree.erase(position); }
- //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
- //!
- //! <b>Returns</b>: Returns the number of erased elements.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus erasure time
- //! linear to the elements with bigger keys.
- size_type erase(const key_type& x)
- { return m_flat_tree.erase(x); }
- //! <b>Effects</b>: Erases all the elements in the range [first, last).
- //!
- //! <b>Returns</b>: Returns last.
- //!
- //! <b>Complexity</b>: size()*N where N is the distance from first to last.
- //!
- //! <b>Complexity</b>: Logarithmic search time plus erasure time
- //! linear to the elements with bigger keys.
- iterator erase(const_iterator first, const_iterator last)
- { return m_flat_tree.erase(first, last); }
- //! <b>Effects</b>: Swaps the contents of *this and x.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- void swap(flat_multiset& x)
- { m_flat_tree.swap(x.m_flat_tree); }
- //! <b>Effects</b>: erase(a.begin(),a.end()).
- //!
- //! <b>Postcondition</b>: size() == 0.
- //!
- //! <b>Complexity</b>: linear in size().
- void clear() BOOST_CONTAINER_NOEXCEPT
- { m_flat_tree.clear(); }
- //////////////////////////////////////////////
- //
- // observers
- //
- //////////////////////////////////////////////
- //! <b>Effects</b>: Returns the comparison object out
- //! of which a was constructed.
- //!
- //! <b>Complexity</b>: Constant.
- key_compare key_comp() const
- { return m_flat_tree.key_comp(); }
- //! <b>Effects</b>: Returns an object of value_compare constructed out
- //! of the comparison object.
- //!
- //! <b>Complexity</b>: Constant.
- value_compare value_comp() const
- { return m_flat_tree.key_comp(); }
- //////////////////////////////////////////////
- //
- // set operations
- //
- //////////////////////////////////////////////
- //! <b>Returns</b>: An iterator pointing to an element with the key
- //! equivalent to x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic.
- iterator find(const key_type& x)
- { return m_flat_tree.find(x); }
- //! <b>Returns</b>: Allocator const_iterator pointing to an element with the key
- //! equivalent to x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic.s
- const_iterator find(const key_type& x) const
- { return m_flat_tree.find(x); }
- //! <b>Returns</b>: The number of elements with key equivalent to x.
- //!
- //! <b>Complexity</b>: log(size())+count(k)
- size_type count(const key_type& x) const
- { return m_flat_tree.count(x); }
- //! <b>Returns</b>: An iterator pointing to the first element with key not less
- //! than k, or a.end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- iterator lower_bound(const key_type& x)
- { return m_flat_tree.lower_bound(x); }
- //! <b>Returns</b>: Allocator const iterator pointing to the first element with key not
- //! less than k, or a.end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- const_iterator lower_bound(const key_type& x) const
- { return m_flat_tree.lower_bound(x); }
- //! <b>Returns</b>: An iterator pointing to the first element with key not less
- //! than x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- iterator upper_bound(const key_type& x)
- { return m_flat_tree.upper_bound(x); }
- //! <b>Returns</b>: Allocator const iterator pointing to the first element with key not
- //! less than x, or end() if such an element is not found.
- //!
- //! <b>Complexity</b>: Logarithmic
- const_iterator upper_bound(const key_type& x) const
- { return m_flat_tree.upper_bound(x); }
- //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
- //!
- //! <b>Complexity</b>: Logarithmic
- std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
- { return m_flat_tree.equal_range(x); }
- //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
- //!
- //! <b>Complexity</b>: Logarithmic
- std::pair<iterator,iterator> equal_range(const key_type& x)
- { return m_flat_tree.equal_range(x); }
- /// @cond
- template <class K1, class C1, class A1>
- friend bool operator== (const flat_multiset<K1,C1,A1>&,
- const flat_multiset<K1,C1,A1>&);
- template <class K1, class C1, class A1>
- friend bool operator< (const flat_multiset<K1,C1,A1>&,
- const flat_multiset<K1,C1,A1>&);
- private:
- template <class KeyType>
- iterator priv_insert(BOOST_FWD_REF(KeyType) x)
- { return m_flat_tree.insert_equal(::boost::forward<KeyType>(x)); }
- template <class KeyType>
- iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x)
- { return m_flat_tree.insert_equal(p, ::boost::forward<KeyType>(x)); }
- /// @endcond
- };
- template <class Key, class Compare, class Allocator>
- inline bool operator==(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y)
- { return x.m_flat_tree == y.m_flat_tree; }
- template <class Key, class Compare, class Allocator>
- inline bool operator<(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y)
- { return x.m_flat_tree < y.m_flat_tree; }
- template <class Key, class Compare, class Allocator>
- inline bool operator!=(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y)
- { return !(x == y); }
- template <class Key, class Compare, class Allocator>
- inline bool operator>(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y)
- { return y < x; }
- template <class Key, class Compare, class Allocator>
- inline bool operator<=(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y)
- { return !(y < x); }
- template <class Key, class Compare, class Allocator>
- inline bool operator>=(const flat_multiset<Key,Compare,Allocator>& x,
- const flat_multiset<Key,Compare,Allocator>& y)
- { return !(x < y); }
- template <class Key, class Compare, class Allocator>
- inline void swap(flat_multiset<Key,Compare,Allocator>& x, flat_multiset<Key,Compare,Allocator>& y)
- { x.swap(y); }
- /// @cond
- } //namespace container {
- //!has_trivial_destructor_after_move<> == true_type
- //!specialization for optimizations
- template <class Key, class C, class Allocator>
- struct has_trivial_destructor_after_move<boost::container::flat_multiset<Key, C, Allocator> >
- {
- static const bool value = has_trivial_destructor_after_move<Allocator>::value && has_trivial_destructor_after_move<C>::value;
- };
- namespace container {
- /// @endcond
- }}
- #include <boost/container/detail/config_end.hpp>
- #endif /* BOOST_CONTAINER_FLAT_SET_HPP */
|