Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-08 08:44:13

0001 ////////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/container for documentation.
0008 //
0009 ////////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_CONTAINER_FLAT_TREE_HPP
0012 #define BOOST_CONTAINER_FLAT_TREE_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/container/detail/config_begin.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024 
0025 #include <boost/container/container_fwd.hpp>
0026 
0027 #include <boost/move/utility_core.hpp>
0028 
0029 #include <boost/container/vector.hpp>
0030 #include <boost/container/allocator_traits.hpp>
0031 
0032 #include <boost/container/detail/value_init.hpp>
0033 #include <boost/container/detail/destroyers.hpp>
0034 #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
0035 #include <boost/container/detail/iterator.hpp>
0036 #include <boost/container/detail/is_sorted.hpp>
0037 #include <boost/container/detail/type_traits.hpp>
0038 #include <boost/container/detail/iterators.hpp>
0039 #include <boost/container/detail/mpl.hpp>
0040 #include <boost/container/detail/is_contiguous_container.hpp>
0041 #include <boost/container/detail/is_container.hpp>
0042 
0043 #include <boost/intrusive/detail/minimal_pair_header.hpp>      //pair
0044 
0045 #include <boost/move/iterator.hpp>
0046 #include <boost/move/adl_move_swap.hpp>
0047 #include <boost/move/detail/iterator_to_raw_pointer.hpp>
0048 #include <boost/move/detail/to_raw_pointer.hpp>
0049 #include <boost/move/detail/force_ptr.hpp>
0050 #include <boost/move/detail/launder.hpp>
0051 #include <boost/move/algo/adaptive_sort.hpp>
0052 #include <boost/move/algo/detail/pdqsort.hpp>
0053 
0054 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0055 #include <boost/move/detail/fwd_macros.hpp>
0056 #endif
0057 
0058 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
0059 
0060 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
0061 #pragma GCC diagnostic push
0062 #pragma GCC diagnostic ignored "-Wunused-result"
0063 #endif
0064 
0065 //merge_unique
0066 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME merge_unique
0067 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
0068 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END   }}}
0069 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 3
0070 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 3
0071 #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
0072 
0073 //merge_equal
0074 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME merge
0075 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
0076 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END   }}}
0077 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 3
0078 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 3
0079 #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
0080 
0081 //index_of
0082 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME index_of
0083 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
0084 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END   }}}
0085 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
0086 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
0087 #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
0088 
0089 //nth
0090 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME nth
0091 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
0092 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END   }}}
0093 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
0094 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
0095 #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
0096 
0097 //reserve
0098 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME reserve
0099 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
0100 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END   }}}
0101 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
0102 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
0103 #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
0104 
0105 //capacity
0106 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME capacity
0107 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
0108 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END   }}}
0109 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 0
0110 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0
0111 #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
0112 
0113 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
0114 #pragma GCC diagnostic pop
0115 #endif
0116 
0117 
0118 #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
0119 
0120 namespace boost {
0121 namespace container {
0122 namespace dtl {
0123 
0124 
0125 ///////////////////////////////////////
0126 //
0127 // Helper functions to merge elements
0128 //
0129 ///////////////////////////////////////
0130 
0131 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(stored_allocator_type)
0132 
0133 ///////////////////////////////////////
0134 //
0135 //  flat_tree_container_inplace_merge
0136 //
0137 ///////////////////////////////////////
0138 template<class SequenceContainer, class Compare>
0139 inline void flat_tree_container_inplace_merge //is_contiguous_container == true
0140    (SequenceContainer& dest, typename SequenceContainer::iterator it, Compare comp , dtl::true_)
0141 {
0142    typedef typename SequenceContainer::value_type value_type;
0143    typedef typename SequenceContainer::size_type  size_type;
0144 
0145    value_type *const braw = boost::movelib::to_raw_pointer(dest.data());
0146    value_type *const iraw = boost::movelib::iterator_to_raw_pointer(it);
0147    //Don't use iterator_to_raw_pointer for end as debug iterators can assert when
0148    //"operator ->" is used with the end iterator
0149    value_type *const eraw = braw + dest.size();
0150    size_type dest_unused_storage_size = 0;
0151    value_type *const dest_unused_storage_addr =
0152       unused_storage<SequenceContainer>::get(dest, dest_unused_storage_size);
0153    boost::movelib::adaptive_merge
0154       (braw, iraw, eraw, comp, dest_unused_storage_addr, dest_unused_storage_size);
0155 }
0156 
0157 template<class SequenceContainer, class Compare>
0158 inline void flat_tree_container_inplace_merge //is_contiguous_container == false
0159    (SequenceContainer& dest, typename SequenceContainer::iterator it, Compare comp, dtl::false_)
0160 {
0161    boost::movelib::adaptive_merge(dest.begin(), it, dest.end(), comp);
0162 }
0163 
0164 ///////////////////////////////////////
0165 //
0166 //  flat_tree_container_inplace_sort_ending
0167 //
0168 ///////////////////////////////////////
0169 template<class SequenceContainer, class Compare>
0170 inline void flat_tree_container_inplace_sort_ending //is_contiguous_container == true
0171    (SequenceContainer& dest, typename SequenceContainer::iterator it, Compare comp, dtl::true_)
0172 {
0173    typedef typename SequenceContainer::value_type value_type;
0174    typedef typename SequenceContainer::size_type  size_type;
0175 
0176    value_type *const iraw = boost::movelib::iterator_to_raw_pointer(it);
0177    //Don't use iterator_to_raw_pointer for end as debug iterators can assert when
0178    //"operator ->" is used with the end iterator
0179    value_type* const eraw = boost::movelib::to_raw_pointer(dest.data()) + dest.size();
0180 
0181    size_type dest_unused_storage_size;
0182    value_type* const dest_unused_storage_addr =
0183       unused_storage<SequenceContainer>::get(dest, dest_unused_storage_size);
0184    boost::movelib::adaptive_sort
0185       (iraw, eraw, comp, dest_unused_storage_addr, dest_unused_storage_size);
0186 }
0187 
0188 template<class SequenceContainer, class Compare>
0189 inline void flat_tree_container_inplace_sort_ending //is_contiguous_container == false
0190    (SequenceContainer& dest, typename SequenceContainer::iterator it, Compare comp , dtl::false_)
0191 {
0192    boost::movelib::adaptive_sort(it, dest.end(), comp);
0193 }
0194 
0195 ///////////////////////////////////////
0196 //
0197 //          flat_tree_merge
0198 //
0199 ///////////////////////////////////////
0200 template<class SequenceContainer, class Iterator, class Compare>
0201 inline void flat_tree_merge_equal
0202    (SequenceContainer& dest, Iterator first, Iterator last, Compare comp, dtl::true_)
0203 {
0204    dest.merge(first, last, comp);
0205 }
0206 
0207 template<class SequenceContainer, class Iterator, class Compare>
0208 inline void flat_tree_merge_equal   //has_merge_unique == false
0209    (SequenceContainer& dest, Iterator first, Iterator last, Compare comp, dtl::false_)
0210 {
0211    if(first != last) {
0212       typedef typename SequenceContainer::iterator    iterator;
0213       iterator const it = dest.insert( dest.end(), first, last);
0214       BOOST_ASSERT((is_sorted)(it, dest.end(), comp));
0215       dtl::bool_<is_contiguous_container<SequenceContainer>::value> contiguous_tag;
0216       (flat_tree_container_inplace_merge)(dest, it, comp, contiguous_tag);
0217    }
0218 }
0219 
0220 ///////////////////////////////////////
0221 //
0222 //       flat_tree_merge_unique
0223 //
0224 ///////////////////////////////////////
0225 template<class SequenceContainer, class Iterator, class Compare>
0226 inline void flat_tree_merge_unique  //has_merge_unique == true
0227    (SequenceContainer& dest, Iterator first, Iterator last, Compare comp, dtl::true_)
0228 {
0229    dest.merge_unique(first, last, comp);
0230 }
0231 
0232 template<class SequenceContainer, class Iterator, class Compare>
0233 inline void flat_tree_merge_unique  //has_merge_unique == false
0234    (SequenceContainer& dest, Iterator first, Iterator last, Compare comp, dtl::false_)
0235 {
0236    if (first != last) {
0237       typedef typename SequenceContainer::iterator          iterator;
0238       typedef typename SequenceContainer::size_type         size_type;
0239       typedef typename SequenceContainer::difference_type   difference_type;
0240 
0241       size_type const old_sz = dest.size();
0242       iterator const first_new = dest.insert(dest.cend(), first, last);
0243       //We can't assert "is_sorted_and_unique" because the sequence can come from a multiset
0244       BOOST_ASSERT((is_sorted)(first_new, dest.end(), comp));
0245       iterator e = boost::movelib::inplace_set_unique_difference(first_new, dest.end(), dest.begin(), first_new, comp);
0246       dest.erase(e, dest.end());
0247       dtl::bool_<is_contiguous_container<SequenceContainer>::value> contiguous_tag;
0248       (flat_tree_container_inplace_merge)(dest, dest.begin() + difference_type(old_sz), comp, contiguous_tag);
0249    }
0250 }
0251 
0252 ///////////////////////////////////////
0253 //
0254 //         flat_tree_index_of
0255 //
0256 ///////////////////////////////////////
0257 template<class SequenceContainer, class Iterator>
0258 inline typename SequenceContainer::size_type
0259    flat_tree_index_of   // has_index_of == true
0260       (SequenceContainer& cont, Iterator p, dtl::true_)
0261 {
0262    return cont.index_of(p);
0263 }
0264 
0265 template<class SequenceContainer, class Iterator>
0266 inline typename SequenceContainer::size_type
0267    flat_tree_index_of   // has_index_of == false
0268       (SequenceContainer& cont, Iterator p, dtl::false_)
0269 {
0270    typedef typename SequenceContainer::size_type size_type;
0271    return static_cast<size_type>(p - cont.begin());
0272 }
0273 
0274 ///////////////////////////////////////
0275 //
0276 //         flat_tree_nth
0277 //
0278 ///////////////////////////////////////
0279 template<class Iterator, class SequenceContainer>
0280 inline Iterator
0281    flat_tree_nth  // has_nth == true
0282       (SequenceContainer& cont, typename SequenceContainer::size_type n, dtl::true_)
0283 {
0284    return cont.nth(n);
0285 }
0286 
0287 template<class Iterator, class SequenceContainer>
0288 inline Iterator
0289    flat_tree_nth  // has_nth == false
0290       (SequenceContainer& cont, typename SequenceContainer::size_type n, dtl::false_)
0291 {
0292    return cont.begin()+ typename SequenceContainer::difference_type(n);
0293 }
0294 
0295 ///////////////////////////////////////
0296 //
0297 //    flat_tree_get_stored_allocator
0298 //
0299 ///////////////////////////////////////
0300 template<class SequenceContainer>
0301 inline typename SequenceContainer::stored_allocator_type &
0302    flat_tree_get_stored_allocator   // has_get_stored_allocator == true
0303       (SequenceContainer& cont, dtl::true_)
0304 {
0305    return cont.get_stored_allocator();
0306 }
0307 
0308 template<class SequenceContainer>
0309 inline const typename SequenceContainer::stored_allocator_type &
0310    flat_tree_get_stored_allocator   // has_get_stored_allocator == true
0311       (const SequenceContainer& cont, dtl::true_)
0312 {
0313    return cont.get_stored_allocator();
0314 }
0315 
0316 template<class SequenceContainer>
0317 inline typename SequenceContainer::allocator_type
0318    flat_tree_get_stored_allocator   // has_get_stored_allocator == false
0319       (SequenceContainer& cont, dtl::false_)
0320 {
0321    return cont.get_allocator();
0322 }
0323 
0324 ///////////////////////////////////////
0325 //
0326 //    flat_tree_adopt_sequence_equal
0327 //
0328 ///////////////////////////////////////
0329 template<class SequenceContainer, class Compare>
0330 void flat_tree_sort_contiguous_to_adopt // is_contiguous_container == true
0331    (SequenceContainer &tseq, BOOST_RV_REF(SequenceContainer) seq, Compare comp)
0332 {
0333    typedef typename SequenceContainer::value_type value_type;
0334    typedef typename SequenceContainer::size_type  size_type;
0335 
0336    size_type tseq_unused_storage_size, seq_unused_storage_size;
0337    value_type* const tseq_unused_storage_addr =
0338       unused_storage<SequenceContainer>::get(tseq, tseq_unused_storage_size);
0339    value_type* const seq_unused_storage_addr  =
0340       unused_storage<SequenceContainer>::get(seq,  seq_unused_storage_size);
0341 
0342    tseq.clear();
0343    const bool use_tseq_storage = tseq_unused_storage_size > seq_unused_storage_size;
0344 
0345    value_type * const seq_beg = boost::movelib::iterator_to_raw_pointer(seq.data());
0346 
0347    boost::movelib::adaptive_sort
0348       ( seq_beg
0349       , seq_beg + seq.size()
0350       , comp
0351       , use_tseq_storage ? tseq_unused_storage_addr : seq_unused_storage_addr
0352       , use_tseq_storage ? tseq_unused_storage_size : seq_unused_storage_size);
0353 }
0354 
0355 template<class SequenceContainer, class Compare>
0356 inline void flat_tree_adopt_sequence_equal // is_contiguous_container == true
0357    (SequenceContainer &tseq, BOOST_RV_REF(SequenceContainer) seq, Compare comp, dtl::true_)
0358 {
0359    flat_tree_sort_contiguous_to_adopt(tseq, boost::move(seq), comp);
0360    tseq = boost::move(seq);
0361 }
0362 
0363 template<class SequenceContainer, class Compare>
0364 inline void flat_tree_adopt_sequence_equal // is_contiguous_container == false
0365    (SequenceContainer &tseq, BOOST_RV_REF(SequenceContainer) seq, Compare comp, dtl::false_)
0366 {
0367    boost::movelib::adaptive_sort(seq.begin(), seq.end(), comp);
0368    tseq = boost::move(seq);
0369 }
0370 
0371 ///////////////////////////////////////
0372 //
0373 //    flat_tree_adopt_sequence_unique
0374 //
0375 ///////////////////////////////////////
0376 template<class SequenceContainer, class Compare>
0377 void flat_tree_adopt_sequence_unique// is_contiguous_container == true
0378    (SequenceContainer &tseq, BOOST_RV_REF(SequenceContainer) seq, Compare comp, dtl::true_)
0379 {
0380    typedef typename SequenceContainer::value_type value_type;
0381    value_type * const seq_beg = boost::movelib::iterator_to_raw_pointer(seq.data());
0382    boost::movelib::pdqsort
0383       ( seq_beg
0384       , seq_beg + seq.size()
0385       , comp);
0386    seq.erase(boost::movelib::unique
0387       (seq.begin(), seq.end(), boost::movelib::negate<Compare>(comp)), seq.cend());
0388    tseq = boost::move(seq);
0389 }
0390 
0391 template<class SequenceContainer, class Compare>
0392 void flat_tree_adopt_sequence_unique// is_contiguous_container == false
0393    (SequenceContainer &tseq, BOOST_RV_REF(SequenceContainer) seq, Compare comp, dtl::false_)
0394 {
0395    boost::movelib::pdqsort(seq.begin(), seq.end(), comp);
0396    seq.erase(boost::movelib::unique
0397       (seq.begin(), seq.end(), boost::movelib::negate<Compare>(comp)), seq.cend());
0398    tseq = boost::move(seq);
0399 }
0400 
0401 ///////////////////////////////////////
0402 //
0403 //       flat_tree_reserve
0404 //
0405 ///////////////////////////////////////
0406 template<class SequenceContainer>
0407 inline void // has_reserve == true
0408    flat_tree_reserve(SequenceContainer &tseq, typename SequenceContainer::size_type cap, dtl::true_)
0409 {
0410    tseq.reserve(cap);
0411 }
0412 
0413 template<class SequenceContainer>
0414 inline void // has_reserve == false
0415    flat_tree_reserve(SequenceContainer &, typename SequenceContainer::size_type, dtl::false_)
0416 {
0417 }
0418 
0419 ///////////////////////////////////////
0420 //
0421 //       flat_tree_capacity
0422 //
0423 ///////////////////////////////////////
0424 template<class SequenceContainer>   // has_capacity == true
0425 inline typename SequenceContainer::size_type
0426    flat_tree_capacity(const SequenceContainer &tseq, dtl::true_)
0427 {
0428    return tseq.capacity();
0429 }
0430 
0431 template<class SequenceContainer>   // has_capacity == false
0432 inline typename SequenceContainer::size_type
0433    flat_tree_capacity(const SequenceContainer &tseq, dtl::false_)
0434 {
0435    return tseq.size();
0436 }
0437 
0438 ///////////////////////////////////////
0439 //
0440 //       flat_tree_value_compare
0441 //
0442 ///////////////////////////////////////
0443 
0444 template<class Compare, class Value, class KeyOfValue>
0445 class flat_tree_value_compare
0446    : private Compare
0447 {
0448    typedef Value              first_argument_type;
0449    typedef Value              second_argument_type;
0450    typedef bool               return_type;
0451    public:
0452    inline flat_tree_value_compare()
0453       : Compare()
0454    {}
0455 
0456    inline flat_tree_value_compare(const Compare &pred)
0457       : Compare(pred)
0458    {}
0459 
0460    inline bool operator()(const Value& lhs, const Value& rhs) const
0461    {
0462       KeyOfValue key_extract;
0463       return Compare::operator()(key_extract(lhs), key_extract(rhs));
0464    }
0465 
0466    inline const Compare &get_comp() const
0467       {  return *this;  }
0468 
0469    inline Compare &get_comp()
0470       {  return *this;  }
0471 };
0472 
0473 
0474 ///////////////////////////////////////
0475 //
0476 //       select_flat_tree_container_type
0477 //
0478 ///////////////////////////////////////
0479 template < class Value, class AllocatorOrContainer
0480          , bool = boost::container::dtl::is_container<AllocatorOrContainer>::value
0481          >
0482 struct select_flat_tree_container_type
0483 {
0484    typedef AllocatorOrContainer type;
0485 };
0486 
0487 template <class Value, class AllocatorOrVoid>
0488 struct select_flat_tree_container_type<Value, AllocatorOrVoid, false>
0489 {
0490    typedef boost::container::vector<Value, AllocatorOrVoid> type;
0491 };
0492 
0493 
0494 ///////////////////////////////////////
0495 //
0496 //          flat_tree
0497 //
0498 ///////////////////////////////////////
0499 template <class Value, class KeyOfValue,
0500           class Compare, class AllocatorOrContainer>
0501 class flat_tree
0502 {
0503    public:
0504    typedef typename select_flat_tree_container_type<Value, AllocatorOrContainer>::type container_type;
0505    typedef container_type sequence_type;  //For backwards compatibility
0506 
0507    private:
0508    typedef typename container_type::allocator_type        allocator_t;
0509    typedef allocator_traits<allocator_t>                 allocator_traits_type;
0510 
0511    public:
0512    typedef flat_tree_value_compare<Compare, Value, KeyOfValue> value_compare;
0513 
0514    private:
0515    
0516    struct Data
0517       //Inherit from value_compare to do EBO
0518       : public value_compare
0519    {
0520       BOOST_COPYABLE_AND_MOVABLE(Data)
0521 
0522       public:
0523       inline Data()
0524          : value_compare(), m_seq()
0525       {}
0526 
0527       inline explicit Data(const allocator_t &alloc)
0528          : value_compare(), m_seq(alloc)
0529       {}
0530 
0531       inline explicit Data(const Compare &comp)
0532          : value_compare(comp), m_seq()
0533       {}
0534 
0535       inline Data(const Compare &comp, const allocator_t &alloc)
0536          : value_compare(comp), m_seq(alloc)
0537       {}
0538 
0539       inline explicit Data(const Data &d)
0540          : value_compare(static_cast<const value_compare&>(d)), m_seq(d.m_seq)
0541       {}
0542 
0543       inline Data(BOOST_RV_REF(Data) d)
0544          : value_compare(boost::move(static_cast<value_compare&>(d))), m_seq(boost::move(d.m_seq))
0545       {}
0546 
0547       inline Data(const Data &d, const allocator_t &a)
0548          : value_compare(static_cast<const value_compare&>(d)), m_seq(d.m_seq, a)
0549       {}
0550 
0551       inline Data(BOOST_RV_REF(Data) d, const allocator_t &a)
0552          : value_compare(boost::move(static_cast<value_compare&>(d))), m_seq(boost::move(d.m_seq), a)
0553       {}
0554 
0555       Data& operator=(BOOST_COPY_ASSIGN_REF(Data) d)
0556       {
0557          this->value_compare::operator=(d);
0558          m_seq = d.m_seq;
0559          return *this;
0560       }
0561 
0562       Data& operator=(BOOST_RV_REF(Data) d)
0563       {
0564          this->value_compare::operator=(boost::move(static_cast<value_compare &>(d)));
0565          m_seq = boost::move(d.m_seq);
0566          return *this;
0567       }
0568 
0569       void swap(Data &d)
0570       {
0571          value_compare& mycomp    = *this, & othercomp = d;
0572          boost::adl_move_swap(mycomp, othercomp);
0573          this->m_seq.swap(d.m_seq);
0574       }
0575 
0576       container_type m_seq;
0577    };
0578 
0579    Data m_data;
0580    BOOST_COPYABLE_AND_MOVABLE(flat_tree)
0581 
0582    public:
0583 
0584    typedef typename container_type::value_type              value_type;
0585    typedef typename container_type::pointer                 pointer;
0586    typedef typename container_type::const_pointer           const_pointer;
0587    typedef typename container_type::reference               reference;
0588    typedef typename container_type::const_reference         const_reference;
0589    typedef typename KeyOfValue::type                        key_type;
0590    typedef Compare                                          key_compare;
0591    typedef typename container_type::allocator_type          allocator_type;
0592    typedef typename container_type::size_type               size_type;
0593    typedef typename container_type::difference_type         difference_type;
0594    typedef typename container_type::iterator                iterator;
0595    typedef typename container_type::const_iterator          const_iterator;
0596    typedef typename container_type::reverse_iterator        reverse_iterator;
0597    typedef typename container_type::const_reverse_iterator  const_reverse_iterator;
0598 
0599    //`allocator_type::value_type` must match container's `value type`. If this
0600    //assertion fails, please review your allocator definition. 
0601    BOOST_CONTAINER_STATIC_ASSERT((is_same<value_type, typename allocator_traits_type::value_type>::value));
0602 
0603    //!Standard extension
0604    typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0605       (boost::container::dtl::, container_type
0606       ,stored_allocator_type, allocator_type)               stored_allocator_type;
0607 
0608    BOOST_STATIC_CONSTEXPR bool has_stored_allocator_type =
0609       BOOST_INTRUSIVE_HAS_TYPE(boost::container::dtl::, container_type, stored_allocator_type);
0610 
0611    private:
0612    typedef allocator_traits<stored_allocator_type> stored_allocator_traits;
0613 
0614    public:
0615    typedef typename dtl::if_c
0616       <has_stored_allocator_type, const stored_allocator_type &, allocator_type>::type get_stored_allocator_const_return_t;
0617 
0618    typedef typename dtl::if_c
0619       <has_stored_allocator_type, stored_allocator_type &, allocator_type>::type get_stored_allocator_noconst_return_t;
0620 
0621    inline flat_tree()
0622       : m_data()
0623    { }
0624 
0625    inline explicit flat_tree(const Compare& comp)
0626       : m_data(comp)
0627    { }
0628 
0629    inline explicit flat_tree(const allocator_type& a)
0630       : m_data(a)
0631    { }
0632 
0633    inline flat_tree(const Compare& comp, const allocator_type& a)
0634       : m_data(comp, a)
0635    { }
0636 
0637    inline flat_tree(const flat_tree& x)
0638       :  m_data(x.m_data)
0639    { }
0640 
0641    inline flat_tree(BOOST_RV_REF(flat_tree) x)
0642       BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
0643       :  m_data(boost::move(x.m_data))
0644    { }
0645 
0646    inline flat_tree(const flat_tree& x, const allocator_type &a)
0647       :  m_data(x.m_data, a)
0648    { }
0649 
0650    inline flat_tree(BOOST_RV_REF(flat_tree) x, const allocator_type &a)
0651       :  m_data(boost::move(x.m_data), a)
0652    { }
0653 
0654    template <class InputIterator>
0655    inline
0656    flat_tree( ordered_range_t, InputIterator first, InputIterator last)
0657       : m_data()
0658    {
0659       this->m_data.m_seq.insert(this->m_data.m_seq.end(), first, last);
0660       BOOST_ASSERT((is_sorted)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp()));
0661    }
0662 
0663    template <class InputIterator>
0664    inline
0665    flat_tree( ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
0666       : m_data(comp)
0667    {
0668       this->m_data.m_seq.insert(this->m_data.m_seq.end(), first, last);
0669       BOOST_ASSERT((is_sorted)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp()));
0670    }
0671 
0672    template <class InputIterator>
0673    inline
0674    flat_tree( ordered_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
0675       : m_data(comp, a)
0676    {
0677       this->m_data.m_seq.insert(this->m_data.m_seq.end(), first, last);
0678       BOOST_ASSERT((is_sorted)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp()));
0679    }
0680 
0681    template <class InputIterator>
0682    inline
0683    flat_tree( ordered_unique_range_t, InputIterator first, InputIterator last)
0684       : m_data()
0685    {
0686       this->m_data.m_seq.insert(this->m_data.m_seq.end(), first, last);
0687       BOOST_ASSERT((is_sorted_and_unique)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp()));
0688    }
0689 
0690    template <class InputIterator>
0691    inline
0692    flat_tree( ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
0693       : m_data(comp)
0694    {
0695       this->m_data.m_seq.insert(this->m_data.m_seq.end(), first, last);
0696       BOOST_ASSERT((is_sorted_and_unique)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp()));
0697    }
0698 
0699    template <class InputIterator>
0700    inline
0701    flat_tree( ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
0702       : m_data(comp, a)
0703    {
0704       this->m_data.m_seq.insert(this->m_data.m_seq.end(), first, last);
0705       BOOST_ASSERT((is_sorted_and_unique)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp()));
0706    }
0707 
0708    template <class InputIterator>
0709    inline
0710    flat_tree( bool unique_insertion, InputIterator first, InputIterator last)
0711       : m_data()
0712    {
0713       this->priv_range_insertion_construct(unique_insertion, first, last);
0714    }
0715 
0716    template <class InputIterator>
0717    inline
0718    flat_tree( bool unique_insertion, InputIterator first, InputIterator last
0719             , const Compare& comp)
0720       : m_data(comp)
0721    {
0722       this->priv_range_insertion_construct(unique_insertion, first, last);
0723    }
0724 
0725    template <class InputIterator>
0726    inline
0727    flat_tree( bool unique_insertion, InputIterator first, InputIterator last
0728             , const allocator_type& a)
0729       : m_data(a)
0730    {
0731       this->priv_range_insertion_construct(unique_insertion, first, last);
0732    }
0733 
0734    template <class InputIterator>
0735    inline
0736    flat_tree( bool unique_insertion, InputIterator first, InputIterator last
0737             , const Compare& comp, const allocator_type& a)
0738       : m_data(comp, a)
0739    {
0740       this->priv_range_insertion_construct(unique_insertion, first, last);
0741    }
0742 
0743    inline ~flat_tree()
0744    {
0745    }
0746 
0747    inline flat_tree&  operator=(BOOST_COPY_ASSIGN_REF(flat_tree) x)
0748    {  m_data = x.m_data;   return *this;  }
0749 
0750    inline flat_tree&  operator=(BOOST_RV_REF(flat_tree) x)
0751       BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
0752                           allocator_traits_type::is_always_equal::value) &&
0753                            boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
0754    {  m_data = boost::move(x.m_data); return *this;  }
0755 
0756    inline const value_compare &priv_value_comp() const
0757    { return static_cast<const value_compare &>(this->m_data); }
0758 
0759    inline value_compare &priv_value_comp()
0760    { return static_cast<value_compare &>(this->m_data); }
0761 
0762    inline const key_compare &priv_key_comp() const
0763    { return this->priv_value_comp().get_comp(); }
0764 
0765    inline key_compare &priv_key_comp()
0766    { return this->priv_value_comp().get_comp(); }
0767 
0768    struct insert_commit_data
0769    {
0770       const_iterator position;
0771    };
0772 
0773    public:
0774    // accessors:
0775    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0776       Compare key_comp() const
0777    { return this->m_data.get_comp(); }
0778 
0779    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0780       value_compare value_comp() const
0781    { return this->m_data; }
0782 
0783    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0784       allocator_type get_allocator() const
0785    { return this->m_data.m_seq.get_allocator(); }
0786 
0787    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0788       get_stored_allocator_const_return_t get_stored_allocator() const
0789    {
0790       return flat_tree_get_stored_allocator(this->m_data.m_seq, dtl::bool_<has_stored_allocator_type>());
0791    }
0792 
0793    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0794       get_stored_allocator_noconst_return_t get_stored_allocator()
0795    {
0796       return flat_tree_get_stored_allocator(this->m_data.m_seq, dtl::bool_<has_stored_allocator_type>());
0797    }
0798 
0799    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0800       iterator begin()
0801    { return this->m_data.m_seq.begin(); }
0802 
0803    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0804       const_iterator begin() const
0805    { return this->cbegin(); }
0806 
0807    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0808       const_iterator cbegin() const
0809    { return this->m_data.m_seq.begin(); }
0810 
0811    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0812       iterator end()
0813    { return this->m_data.m_seq.end(); }
0814 
0815    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0816       const_iterator end() const
0817    { return this->cend(); }
0818 
0819    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0820       const_iterator cend() const
0821    { return this->m_data.m_seq.end(); }
0822 
0823    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0824       reverse_iterator rbegin()
0825    { return reverse_iterator(this->end()); }
0826 
0827    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0828       const_reverse_iterator rbegin() const
0829    {  return this->crbegin();  }
0830 
0831    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0832       const_reverse_iterator crbegin() const
0833    {  return const_reverse_iterator(this->cend());  }
0834 
0835    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0836       reverse_iterator rend()
0837    { return reverse_iterator(this->begin()); }
0838 
0839    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0840       const_reverse_iterator rend() const
0841    { return this->crend(); }
0842 
0843    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0844       const_reverse_iterator crend() const
0845    { return const_reverse_iterator(this->cbegin()); }
0846 
0847    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0848       bool empty() const
0849    { return this->m_data.m_seq.empty(); }
0850 
0851    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0852       size_type size() const
0853    { return this->m_data.m_seq.size(); }
0854 
0855    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
0856       size_type max_size() const
0857    { return this->m_data.m_seq.max_size(); }
0858 
0859    inline void swap(flat_tree& other)
0860       BOOST_NOEXCEPT_IF(  allocator_traits_type::is_always_equal::value
0861                                  && boost::container::dtl::is_nothrow_swappable<Compare>::value )
0862    {  this->m_data.swap(other.m_data);  }
0863 
0864    public:
0865    // insert/erase
0866    std::pair<iterator,bool> insert_unique(const value_type& val)
0867    {
0868       std::pair<iterator,bool> ret;
0869       insert_commit_data data;
0870       ret.second = this->priv_insert_unique_prepare(KeyOfValue()(val), data);
0871       ret.first = ret.second ? this->priv_insert_commit(data, val)
0872                              : this->begin() + (data.position - this->cbegin());
0873                              //: iterator(vector_iterator_get_ptr(data.position));
0874       return ret;
0875    }
0876 
0877    std::pair<iterator,bool> insert_unique(BOOST_RV_REF(value_type) val)
0878    {
0879       std::pair<iterator,bool> ret;
0880       insert_commit_data data;
0881       ret.second = this->priv_insert_unique_prepare(KeyOfValue()(val), data);
0882       ret.first = ret.second ? this->priv_insert_commit(data, boost::move(val))
0883                              : this->begin() + (data.position - this->cbegin());
0884                              //: iterator(vector_iterator_get_ptr(data.position));
0885       return ret;
0886    }
0887 
0888    iterator insert_equal(const value_type& val)
0889    {
0890       iterator i = this->upper_bound(KeyOfValue()(val));
0891       i = this->m_data.m_seq.insert(i, val);
0892       return i;
0893    }
0894 
0895    iterator insert_equal(BOOST_RV_REF(value_type) mval)
0896    {
0897       iterator i = this->upper_bound(KeyOfValue()(mval));
0898       i = this->m_data.m_seq.insert(i, boost::move(mval));
0899       return i;
0900    }
0901 
0902    iterator insert_unique(const_iterator hint, const value_type& val)
0903    {
0904       BOOST_ASSERT(this->priv_in_range_or_end(hint));
0905       insert_commit_data data;
0906       return this->priv_insert_unique_prepare(hint, KeyOfValue()(val), data)
0907             ? this->priv_insert_commit(data, val)
0908             : this->begin() + (data.position - this->cbegin());
0909             //: iterator(vector_iterator_get_ptr(data.position));
0910    }
0911 
0912    iterator insert_unique(const_iterator hint, BOOST_RV_REF(value_type) val)
0913    {
0914       BOOST_ASSERT(this->priv_in_range_or_end(hint));
0915       insert_commit_data data;
0916       return this->priv_insert_unique_prepare(hint, KeyOfValue()(val), data)
0917          ? this->priv_insert_commit(data, boost::move(val))
0918          : this->begin() + (data.position - this->cbegin());
0919          //: iterator(vector_iterator_get_ptr(data.position));
0920    }
0921 
0922    iterator insert_equal(const_iterator hint, const value_type& val)
0923    {
0924       BOOST_ASSERT(this->priv_in_range_or_end(hint));
0925       insert_commit_data data;
0926       this->priv_insert_equal_prepare(hint, val, data);
0927       return this->priv_insert_commit(data, val);
0928    }
0929 
0930    iterator insert_equal(const_iterator hint, BOOST_RV_REF(value_type) mval)
0931    {
0932       BOOST_ASSERT(this->priv_in_range_or_end(hint));
0933       insert_commit_data data;
0934       this->priv_insert_equal_prepare(hint, mval, data);
0935       return this->priv_insert_commit(data, boost::move(mval));
0936    }
0937 
0938    template <class InIt>
0939    void insert_unique(InIt first, InIt last)
0940    {
0941       dtl::bool_<is_contiguous_container<container_type>::value> contiguous_tag;
0942       container_type &seq = this->m_data.m_seq;
0943       value_compare &val_cmp = this->priv_value_comp();
0944 
0945       //Step 1: put new elements in the back
0946       typename container_type::iterator const it = seq.insert(seq.cend(), first, last);
0947 
0948       //Step 2: sort them
0949       boost::movelib::pdqsort(it, seq.end(), val_cmp);
0950 
0951       //Step 3: only left unique values from the back not already present in the original range
0952       typename container_type::iterator const e = boost::movelib::inplace_set_unique_difference
0953          (it, seq.end(), seq.begin(), it, val_cmp);
0954 
0955       //it might be invalidated by erasing [e, seq.end) if e == it, so check it before
0956       const bool remaining = e != it;
0957       seq.erase(e, seq.cend());
0958       if (remaining)
0959       {
0960          //Step 4: merge both ranges
0961          (flat_tree_container_inplace_merge)(seq, it, this->priv_value_comp(), contiguous_tag);
0962       }
0963    }
0964 
0965    template <class InIt>
0966    void insert_equal(InIt first, InIt last)
0967    {
0968       if (first != last) {
0969          dtl::bool_<is_contiguous_container<container_type>::value> contiguous_tag;
0970          container_type &seq = this->m_data.m_seq;
0971          typename container_type::iterator const it = seq.insert(seq.cend(), first, last);
0972          (flat_tree_container_inplace_sort_ending)(seq, it, this->priv_value_comp(), contiguous_tag);
0973          (flat_tree_container_inplace_merge)      (seq, it, this->priv_value_comp(), contiguous_tag);
0974       }
0975    }
0976 
0977    //Ordered
0978 
0979    template <class InIt>
0980    void insert_equal(ordered_range_t, InIt first, InIt last)
0981    {
0982       const bool value = boost::container::dtl::
0983          has_member_function_callable_with_merge_unique<container_type, InIt, InIt, value_compare>::value;
0984       (flat_tree_merge_equal)(this->m_data.m_seq, first, last, this->priv_value_comp(), dtl::bool_<value>());
0985    }
0986 
0987    template <class InIt>
0988    void insert_unique(ordered_unique_range_t, InIt first, InIt last)
0989    {
0990       const bool value = boost::container::dtl::
0991          has_member_function_callable_with_merge_unique<container_type, InIt, InIt, value_compare>::value;
0992       (flat_tree_merge_unique)(this->m_data.m_seq, first, last, this->priv_value_comp(), dtl::bool_<value>());
0993    }
0994 
0995    #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0996 
0997    template <class... Args>
0998    std::pair<iterator, bool> emplace_unique(BOOST_FWD_REF(Args)... args)
0999    {
1000       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
1001       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
1002       stored_allocator_traits::construct(a, (value_type *)(&v), ::boost::forward<Args>(args)... );
1003       value_type *pval = move_detail::launder_cast<value_type *>(&v);
1004       value_destructor<stored_allocator_type, value_type> d(a, *pval);
1005       return this->insert_unique(::boost::move(*pval));
1006    }
1007 
1008    template <class... Args>
1009    iterator emplace_hint_unique(const_iterator hint, BOOST_FWD_REF(Args)... args)
1010    {
1011       //hint checked in insert_unique
1012       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
1013       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
1014       stored_allocator_traits::construct(a, (value_type*)(&v), ::boost::forward<Args>(args)... );
1015       value_type *pval = move_detail::launder_cast<value_type *>(&v);
1016       value_destructor<stored_allocator_type, value_type> d(a, *pval);
1017       return this->insert_unique(hint, ::boost::move(*pval));
1018    }
1019 
1020    template <class... Args>
1021    iterator emplace_equal(BOOST_FWD_REF(Args)... args)
1022    {
1023       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
1024       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
1025       stored_allocator_traits::construct(a, (value_type*)(&v), ::boost::forward<Args>(args)... );
1026       value_type *pval = move_detail::launder_cast<value_type *>(&v);
1027       value_destructor<stored_allocator_type, value_type> d(a, *pval);
1028       return this->insert_equal(::boost::move(*pval));
1029    }
1030 
1031    template <class... Args>
1032    iterator emplace_hint_equal(const_iterator hint, BOOST_FWD_REF(Args)... args)
1033    {
1034       //hint checked in insert_equal
1035       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;
1036       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();
1037       stored_allocator_traits::construct(a, (value_type*)(&v), ::boost::forward<Args>(args)... );
1038       value_type *pval = move_detail::launder_cast<value_type *>(&v);
1039       value_destructor<stored_allocator_type, value_type> d(a, *pval);
1040       return this->insert_equal(hint, ::boost::move(*pval));
1041    }
1042 
1043    template <class KeyType, class... Args>
1044    inline std::pair<iterator, bool> try_emplace
1045       (const_iterator hint, BOOST_FWD_REF(KeyType) key, BOOST_FWD_REF(Args)... args)
1046    {
1047       std::pair<iterator,bool> ret;
1048       insert_commit_data data;
1049       const key_type & k = key;
1050       ret.second = hint == const_iterator()
1051          ? this->priv_insert_unique_prepare(k, data)
1052          : this->priv_insert_unique_prepare(hint, k, data);
1053 
1054       if(!ret.second){
1055          ret.first  = this->nth(size_type(data.position - this->cbegin()));
1056       }
1057       else{
1058          ret.first = this->m_data.m_seq.emplace(data.position, try_emplace_t(), ::boost::forward<KeyType>(key), ::boost::forward<Args>(args)...);
1059       }
1060       return ret;
1061    }
1062 
1063    #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1064 
1065    #define BOOST_CONTAINER_FLAT_TREE_EMPLACE_CODE(N) \
1066    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1067    std::pair<iterator, bool> emplace_unique(BOOST_MOVE_UREF##N)\
1068    {\
1069       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
1070       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
1071       stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1072       value_type *pval = move_detail::launder_cast<value_type *>(&v);\
1073       value_destructor<stored_allocator_type, value_type> d(a, *pval);\
1074       return this->insert_unique(::boost::move(*pval));\
1075    }\
1076    \
1077    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1078    iterator emplace_hint_unique(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1079    {\
1080       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
1081       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
1082       stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1083       value_type *pval = move_detail::launder_cast<value_type *>(&v);\
1084       value_destructor<stored_allocator_type, value_type> d(a, *pval);\
1085       return this->insert_unique(hint, ::boost::move(*pval));\
1086    }\
1087    \
1088    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1089    iterator emplace_equal(BOOST_MOVE_UREF##N)\
1090    {\
1091       typename dtl::aligned_storage<sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
1092       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
1093       stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1094       value_type *pval = move_detail::launder_cast<value_type *>(&v);\
1095       value_destructor<stored_allocator_type, value_type> d(a, *pval);\
1096       return this->insert_equal(::boost::move(*pval));\
1097    }\
1098    \
1099    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1100    iterator emplace_hint_equal(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1101    {\
1102       typename dtl::aligned_storage <sizeof(value_type), dtl::alignment_of<value_type>::value>::type v;\
1103       get_stored_allocator_noconst_return_t a = this->get_stored_allocator();\
1104       stored_allocator_traits::construct(a, (value_type *)(&v) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1105       value_type *pval = move_detail::launder_cast<value_type *>(&v);\
1106       value_destructor<stored_allocator_type, value_type> d(a, *pval);\
1107       return this->insert_equal(hint, ::boost::move(*pval));\
1108    }\
1109    template <class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
1110    inline std::pair<iterator, bool>\
1111       try_emplace(const_iterator hint, BOOST_FWD_REF(KeyType) key BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1112    {\
1113       std::pair<iterator,bool> ret;\
1114       insert_commit_data data;\
1115       const key_type & k = key;\
1116       ret.second = hint == const_iterator()\
1117          ? this->priv_insert_unique_prepare(k, data)\
1118          : this->priv_insert_unique_prepare(hint, k, data);\
1119       \
1120       if(!ret.second){\
1121          ret.first  = this->nth(size_type(data.position - this->cbegin()));\
1122       }\
1123       else{\
1124          ret.first = this->m_data.m_seq.emplace(data.position, try_emplace_t(), ::boost::forward<KeyType>(key) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1125       }\
1126       return ret;\
1127    }\
1128    //
1129    BOOST_MOVE_ITERATE_0TO7(BOOST_CONTAINER_FLAT_TREE_EMPLACE_CODE)
1130    #undef BOOST_CONTAINER_FLAT_TREE_EMPLACE_CODE
1131 
1132    #endif   // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1133 
1134    template<class KeyType, class M>
1135    std::pair<iterator, bool> insert_or_assign(const_iterator hint, BOOST_FWD_REF(KeyType) key, BOOST_FWD_REF(M) obj)
1136    {
1137       const key_type& k = key;
1138       std::pair<iterator,bool> ret;
1139       insert_commit_data data;
1140       ret.second = hint == const_iterator()
1141          ? this->priv_insert_unique_prepare(k, data)
1142          : this->priv_insert_unique_prepare(hint, k, data);
1143       if(!ret.second){
1144          ret.first  = this->nth(size_type(data.position - this->cbegin()));
1145          ret.first->second = boost::forward<M>(obj);
1146       }
1147       else{
1148          ret.first = this->m_data.m_seq.emplace(data.position, boost::forward<KeyType>(key), boost::forward<M>(obj));
1149       }
1150       return ret;
1151    }
1152 
1153    size_type erase(const key_type& k)
1154    {
1155       std::pair<iterator,iterator > itp = this->equal_range(k);
1156       size_type ret = static_cast<size_type>(itp.second-itp.first);
1157       if (ret){
1158          this->m_data.m_seq.erase(itp.first, itp.second);
1159       }
1160       return ret;
1161    }
1162 
1163    size_type erase_unique(const key_type& k)
1164    {
1165       const_iterator i = static_cast<const flat_tree &>(*this).find(k);
1166       size_type ret = static_cast<size_type>(i != this->cend());
1167       if (ret)
1168          this->erase(i);
1169       return ret;
1170    }
1171 
1172    template <class K>
1173    inline typename dtl::enable_if_c<
1174       dtl::is_transparent<key_compare>::value &&      //transparent
1175       !dtl::is_convertible<K, iterator>::value &&     //not convertible to iterator
1176       !dtl::is_convertible<K, const_iterator>::value  //not convertible to const_iterator
1177       , size_type>::type
1178       erase(BOOST_FWD_REF(K) key)
1179    {
1180       const typename remove_cvref<K>::type & k = key;  //Support emulated rvalue references
1181       std::pair<iterator, iterator > itp = this->equal_range(k);
1182       size_type ret = static_cast<size_type>(itp.second - itp.first);
1183       if (ret) {
1184          this->m_data.m_seq.erase(itp.first, itp.second);
1185       }
1186       return ret;
1187    }
1188 
1189    template <class K>
1190    inline typename dtl::enable_if_c<
1191       dtl::is_transparent<key_compare>::value &&      //transparent
1192       !dtl::is_convertible<K, iterator>::value &&     //not convertible to iterator
1193       !dtl::is_convertible<K, const_iterator>::value  //not convertible to const_iterator
1194       , size_type>::type
1195       erase_unique(const K& k)
1196    {
1197       const_iterator i = static_cast<const flat_tree&>(*this).find(k);
1198       size_type ret = static_cast<size_type>(i != this->cend());
1199       if (ret)
1200          this->erase(i);
1201       return ret;
1202    }
1203 
1204    inline iterator erase(const_iterator position)
1205    {  return this->m_data.m_seq.erase(position);  }
1206 
1207    inline iterator erase(const_iterator first, const_iterator last)
1208    {  return this->m_data.m_seq.erase(first, last);  }
1209 
1210    inline void clear()
1211    {  this->m_data.m_seq.clear();  }
1212 
1213    //! <b>Effects</b>: Tries to deallocate the excess of memory created
1214    //    with previous allocations. The size of the vector is unchanged
1215    //!
1216    //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
1217    //!
1218    //! <b>Complexity</b>: Linear to size().
1219    inline void shrink_to_fit()
1220    {  this->m_data.m_seq.shrink_to_fit();  }
1221 
1222    inline iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1223    {
1224       const bool value = boost::container::dtl::
1225          has_member_function_callable_with_nth<container_type, size_type>::value;
1226       return flat_tree_nth<iterator>(this->m_data.m_seq, n, dtl::bool_<value>());
1227    }
1228 
1229    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1230       const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
1231    {
1232       const bool value = boost::container::dtl::
1233          has_member_function_callable_with_nth<container_type, size_type>::value;
1234       return flat_tree_nth<const_iterator>(this->m_data.m_seq, n, dtl::bool_<value>());
1235    }
1236 
1237    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1238       size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
1239    {
1240       const bool value = boost::container::dtl::
1241          has_member_function_callable_with_index_of<container_type, iterator>::value;
1242       return flat_tree_index_of(this->m_data.m_seq, p, dtl::bool_<value>());
1243    }
1244 
1245    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1246       size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
1247    {
1248       const bool value = boost::container::dtl::
1249          has_member_function_callable_with_index_of<container_type, const_iterator>::value;
1250       return flat_tree_index_of(this->m_data.m_seq, p, dtl::bool_<value>());
1251    }
1252 
1253    // set operations:
1254    BOOST_CONTAINER_ATTRIBUTE_NODISCARD
1255       iterator find(const key_type& k)
1256    {
1257       iterator i = this->lower_bound(k);
1258       iterator end_it = this->end();
1259       if (i != end_it && this->m_data.get_comp()(k, KeyOfValue()(*i))){
1260          i = end_it;
1261       }
1262       return i;
1263    }
1264 
1265    BOOST_CONTAINER_ATTRIBUTE_NODISCARD
1266    const_iterator find(const key_type& k) const
1267    {
1268       const_iterator i = this->lower_bound(k);
1269 
1270       const_iterator end_it = this->cend();
1271       if (i != end_it && this->m_data.get_comp()(k, KeyOfValue()(*i))){
1272          i = end_it;
1273       }
1274       return i;
1275    }
1276 
1277    template<class K>
1278    BOOST_CONTAINER_ATTRIBUTE_NODISCARD
1279       typename dtl::enable_if_transparent<key_compare, K, iterator>::type
1280       find(const K& k)
1281    {
1282       iterator i = this->lower_bound(k);
1283       iterator end_it = this->end();
1284       if (i != end_it && this->m_data.get_comp()(k, KeyOfValue()(*i))){
1285          i = end_it;
1286       }
1287       return i;
1288    }
1289 
1290    template<class K>
1291    BOOST_CONTAINER_ATTRIBUTE_NODISCARD
1292       typename dtl::enable_if_transparent<key_compare, K, const_iterator>::type
1293       find(const K& k) const
1294    {
1295       const_iterator i = this->lower_bound(k);
1296 
1297       const_iterator end_it = this->cend();
1298       if (i != end_it && this->m_data.get_comp()(k, KeyOfValue()(*i))){
1299          i = end_it;
1300       }
1301       return i;
1302    }
1303 
1304    BOOST_CONTAINER_ATTRIBUTE_NODISCARD
1305       size_type count(const key_type& k) const
1306    {
1307       std::pair<const_iterator, const_iterator> p = this->equal_range(k);
1308       size_type n = size_type(p.second - p.first);
1309       return n;
1310    }
1311 
1312    template<class K>
1313    BOOST_CONTAINER_ATTRIBUTE_NODISCARD
1314       typename dtl::enable_if_transparent<key_compare, K, size_type>::type
1315       count(const K& k) const
1316    {
1317       std::pair<const_iterator, const_iterator> p = this->equal_range(k);
1318       size_type n = size_type(p.second - p.first);
1319       return n;
1320    }
1321 
1322    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline bool contains(const key_type& x) const
1323    {  return this->find(x) != this->cend();  }
1324 
1325    template<typename K>
1326    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1327       typename dtl::enable_if_transparent<key_compare, K, bool>::type
1328          contains(const K& x) const
1329    {  return this->find(x) != this->cend();  }
1330 
1331    template<class C2>
1332    inline void merge_unique(flat_tree<Value, KeyOfValue, C2, AllocatorOrContainer>& source)
1333    {
1334       this->insert_unique( boost::make_move_iterator(source.begin())
1335                          , boost::make_move_iterator(source.end()));
1336    }
1337 
1338    template<class C2>
1339    inline void merge_equal(flat_tree<Value, KeyOfValue, C2, AllocatorOrContainer>& source)
1340    {
1341       this->insert_equal( boost::make_move_iterator(source.begin())
1342                         , boost::make_move_iterator(source.end()));
1343    }
1344 
1345    inline void merge_unique(flat_tree& source)
1346    {
1347       const bool value = boost::container::dtl::
1348          has_member_function_callable_with_merge_unique<container_type, iterator, iterator, value_compare>::value;
1349       (flat_tree_merge_unique)
1350          ( this->m_data.m_seq
1351          , boost::make_move_iterator(source.m_data.m_seq.begin())
1352          , boost::make_move_iterator(source.m_data.m_seq.end())
1353          , this->priv_value_comp()
1354          , dtl::bool_<value>());
1355    }
1356 
1357    inline void merge_equal(flat_tree& source)
1358    {
1359       const bool value = boost::container::dtl::
1360          has_member_function_callable_with_merge<container_type, iterator, iterator, value_compare>::value;
1361       (flat_tree_merge_equal)
1362          ( this->m_data.m_seq
1363          , boost::make_move_iterator(source.m_data.m_seq.begin())
1364          , boost::make_move_iterator(source.m_data.m_seq.end())
1365          , this->priv_value_comp()
1366          , dtl::bool_<value>());
1367    }
1368 
1369    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1370       iterator lower_bound(const key_type& k)
1371    {  return this->priv_lower_bound(this->begin(), this->end(), k);  }
1372 
1373    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1374       const_iterator lower_bound(const key_type& k) const
1375    {  return this->priv_lower_bound(this->cbegin(), this->cend(), k);  }
1376 
1377    template<class K>
1378    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline 
1379       typename dtl::enable_if_transparent<key_compare, K, iterator>::type
1380          lower_bound(const K& k)
1381    {  return this->priv_lower_bound(this->begin(), this->end(), k);  }
1382 
1383    template<class K>
1384    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline 
1385       typename dtl::enable_if_transparent<key_compare, K, const_iterator>::type
1386          lower_bound(const K& k) const
1387    {  return this->priv_lower_bound(this->cbegin(), this->cend(), k);  }
1388 
1389    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1390       iterator upper_bound(const key_type& k)
1391    {  return this->priv_upper_bound(this->begin(), this->end(), k);  }
1392 
1393    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline 
1394       const_iterator upper_bound(const key_type& k) const
1395    {  return this->priv_upper_bound(this->cbegin(), this->cend(), k);  }
1396 
1397    template<class K>
1398    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1399       typename dtl::enable_if_transparent<key_compare, K,iterator>::type
1400    upper_bound(const K& k)
1401    {  return this->priv_upper_bound(this->begin(), this->end(), k);  }
1402 
1403    template<class K>
1404    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1405       typename dtl::enable_if_transparent<key_compare, K,const_iterator>::type
1406          upper_bound(const K& k) const
1407    {  return this->priv_upper_bound(this->cbegin(), this->cend(), k);  }
1408 
1409    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1410       std::pair<iterator,iterator> equal_range(const key_type& k)
1411    {  return this->priv_equal_range(this->begin(), this->end(), k);  }
1412 
1413    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1414       std::pair<const_iterator, const_iterator> equal_range(const key_type& k) const
1415    {  return this->priv_equal_range(this->cbegin(), this->cend(), k);  }
1416 
1417    template<class K>
1418    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1419       typename dtl::enable_if_transparent<key_compare, K, std::pair<iterator,iterator> >::type
1420          equal_range(const K& k)
1421    {  return this->priv_equal_range(this->begin(), this->end(), k);  }
1422 
1423    template<class K>
1424    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1425       typename dtl::enable_if_transparent<key_compare, K,std::pair<const_iterator,const_iterator> >::type
1426          equal_range(const K& k) const
1427    {  return this->priv_equal_range(this->cbegin(), this->cend(), k);  }
1428 
1429 
1430    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1431       std::pair<iterator, iterator> lower_bound_range(const key_type& k)
1432    {  return this->priv_lower_bound_range(this->begin(), this->end(), k);  }
1433 
1434    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1435       std::pair<const_iterator, const_iterator> lower_bound_range(const key_type& k) const
1436    {  return this->priv_lower_bound_range(this->cbegin(), this->cend(), k);  }
1437 
1438    template<class K>
1439    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1440       typename dtl::enable_if_transparent<key_compare, K,std::pair<iterator,iterator> >::type
1441          lower_bound_range(const K& k)
1442    {  return this->priv_lower_bound_range(this->begin(), this->end(), k);  }
1443 
1444    template<class K>
1445    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1446       typename dtl::enable_if_transparent<key_compare, K,std::pair<const_iterator,const_iterator> >::type
1447          lower_bound_range(const K& k) const
1448    {  return this->priv_lower_bound_range(this->cbegin(), this->cend(), k);  }
1449 
1450    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1451       size_type capacity() const
1452    {
1453       const bool value = boost::container::dtl::
1454          has_member_function_callable_with_capacity<container_type>::value;
1455       return (flat_tree_capacity)(this->m_data.m_seq, dtl::bool_<value>());
1456    }
1457 
1458    inline
1459       void reserve(size_type cnt)
1460    {
1461       const bool value = boost::container::dtl::
1462          has_member_function_callable_with_reserve<container_type, size_type>::value;
1463       (flat_tree_reserve)(this->m_data.m_seq, cnt, dtl::bool_<value>());
1464    }
1465 
1466    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1467       container_type extract_sequence()
1468    {  return boost::move(m_data.m_seq);   }
1469 
1470    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1471       container_type &get_sequence_ref()
1472    {  return m_data.m_seq; }
1473 
1474    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1475       const container_type &get_sequence_cref() const
1476    {  return m_data.m_seq; }
1477 
1478    inline void adopt_sequence_equal(BOOST_RV_REF(container_type) seq)
1479    {
1480       (flat_tree_adopt_sequence_equal)( m_data.m_seq, boost::move(seq), this->priv_value_comp()
1481          , dtl::bool_<is_contiguous_container<container_type>::value>());
1482    }
1483 
1484    inline void adopt_sequence_unique(BOOST_RV_REF(container_type) seq)
1485    {
1486       (flat_tree_adopt_sequence_unique)(m_data.m_seq, boost::move(seq), this->priv_value_comp()
1487          , dtl::bool_<is_contiguous_container<container_type>::value>());
1488    }
1489 
1490    void adopt_sequence_equal(ordered_range_t, BOOST_RV_REF(container_type) seq)
1491    {
1492       BOOST_ASSERT((is_sorted)(seq.cbegin(), seq.cend(), this->priv_value_comp()));
1493       m_data.m_seq = boost::move(seq);
1494    }
1495 
1496    void adopt_sequence_unique(ordered_unique_range_t, BOOST_RV_REF(container_type) seq)
1497    {
1498       BOOST_ASSERT((is_sorted_and_unique)(seq.cbegin(), seq.cend(), this->priv_value_comp()));
1499       m_data.m_seq = boost::move(seq);
1500    }
1501 
1502    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1503       friend bool operator==(const flat_tree& x, const flat_tree& y)
1504    {
1505       return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin());
1506    }
1507 
1508    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1509       friend bool operator<(const flat_tree& x, const flat_tree& y)
1510    {
1511       return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
1512    }
1513 
1514    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1515       friend bool operator!=(const flat_tree& x, const flat_tree& y)
1516       {  return !(x == y); }
1517 
1518    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1519       friend bool operator>(const flat_tree& x, const flat_tree& y)
1520       {  return y < x;  }
1521 
1522    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1523       friend bool operator<=(const flat_tree& x, const flat_tree& y)
1524       {  return !(y < x);  }
1525 
1526    BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
1527       friend bool operator>=(const flat_tree& x, const flat_tree& y)
1528       {  return !(x < y);  }
1529 
1530    inline friend void swap(flat_tree& x, flat_tree& y)
1531           BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
1532       {  x.swap(y);  }
1533 
1534    private:
1535 
1536    template <class InputIterator>
1537    void priv_range_insertion_construct( bool unique_insertion, InputIterator first, InputIterator last)
1538    {
1539       //Use cend() as hint to achieve linear time for
1540       //ordered ranges as required by the standard
1541       //for the constructor
1542       //Call end() every iteration as reallocation might have invalidated iterators
1543       if(unique_insertion){
1544          this->insert_unique(first, last);
1545       }
1546       else{
1547          this->insert_equal (first, last);
1548       }
1549    }
1550 
1551    inline bool priv_in_range_or_end(const_iterator pos) const
1552    {
1553       return (this->begin() <= pos) && (pos <= this->end());
1554    }
1555 
1556    // insert/erase
1557    void priv_insert_equal_prepare
1558       (const_iterator pos, const value_type& val, insert_commit_data &data)
1559    {
1560       // N1780
1561       //   To insert val at pos:
1562       //   if pos == end || val <= *pos
1563       //      if pos == begin || val >= *(pos-1)
1564       //         insert val before pos
1565       //      else
1566       //         insert val before upper_bound(val)
1567       //   else
1568       //      insert val before lower_bound(val)
1569       const value_compare &val_cmp = this->m_data;
1570 
1571       if(pos == this->cend() || !val_cmp(*pos, val)){
1572          if (pos == this->cbegin() || !val_cmp(val, pos[-1])){
1573             data.position = pos;
1574          }
1575          else{
1576             data.position =
1577                this->priv_upper_bound(this->cbegin(), pos, KeyOfValue()(val));
1578          }
1579       }
1580       else{
1581          data.position =
1582             this->priv_lower_bound(pos, this->cend(), KeyOfValue()(val));
1583       }
1584    }
1585 
1586    bool priv_insert_unique_prepare
1587       (const_iterator b, const_iterator e, const key_type& k, insert_commit_data &commit_data)
1588    {
1589       const key_compare &key_cmp  = this->priv_key_comp();
1590       commit_data.position = this->priv_lower_bound(b, e, k);
1591       return commit_data.position == e || key_cmp(k, KeyOfValue()(*commit_data.position));
1592    }
1593 
1594    inline bool priv_insert_unique_prepare
1595       (const key_type& k, insert_commit_data &commit_data)
1596    {  return this->priv_insert_unique_prepare(this->cbegin(), this->cend(), k, commit_data);   }
1597 
1598    bool priv_insert_unique_prepare
1599       (const_iterator pos, const key_type& k, insert_commit_data &commit_data)
1600    {
1601       //N1780. Props to Howard Hinnant!
1602       //To insert k at pos:
1603       //if pos == end || k <= *pos
1604       //   if pos == begin || k >= *(pos-1)
1605       //      insert k before pos
1606       //   else
1607       //      insert k before upper_bound(k)
1608       //else if pos+1 == end || k <= *(pos+1)
1609       //   insert k after pos
1610       //else
1611       //   insert k before lower_bound(k)
1612       const key_compare &key_cmp = this->priv_key_comp();
1613       const const_iterator cend_it = this->cend();
1614       if(pos == cend_it || key_cmp(k, KeyOfValue()(*pos))){ //Check if k should go before end
1615          const const_iterator cbeg = this->cbegin();
1616          commit_data.position = pos;
1617          if(pos == cbeg){  //If container is empty then insert it in the beginning
1618             return true;
1619          }
1620          const_iterator prev(pos);
1621          --prev;
1622          if(key_cmp(KeyOfValue()(*prev), k)){   //If previous element was less, then it should go between prev and pos
1623             return true;
1624          }
1625          else if(!key_cmp(k, KeyOfValue()(*prev))){   //If previous was equal then insertion should fail
1626             commit_data.position = prev;
1627             return false;
1628          }
1629          else{ //Previous was bigger so insertion hint was pointless, dispatch to hintless insertion
1630                //but reduce the search between beg and prev as prev is bigger than k
1631             return this->priv_insert_unique_prepare(cbeg, prev, k, commit_data);
1632          }
1633       }
1634       else{
1635          //The hint is before the insertion position, so insert it
1636          //in the remaining range [pos, end)
1637          return this->priv_insert_unique_prepare(pos, cend_it, k, commit_data);
1638       }
1639    }
1640 
1641    template<class Convertible>
1642    inline iterator priv_insert_commit
1643       (insert_commit_data &commit_data, BOOST_FWD_REF(Convertible) convertible)
1644    {
1645       return this->m_data.m_seq.insert
1646          ( commit_data.position
1647          , boost::forward<Convertible>(convertible));
1648    }
1649 
1650    template <class RanIt, class K>
1651    RanIt priv_lower_bound(RanIt first, const RanIt last,
1652                           const K & key) const
1653    {
1654       const Compare &key_cmp = this->m_data.get_comp();
1655       KeyOfValue key_extract;
1656       size_type len = static_cast<size_type>(last - first);
1657       RanIt middle;
1658 
1659       while (len) {
1660          size_type step = len >> 1;
1661          middle = first;
1662          middle += difference_type(step);
1663 
1664          if (key_cmp(key_extract(*middle), key)) {
1665             first = ++middle;
1666             len -= step + 1;
1667          }
1668          else{
1669             len = step;
1670          }
1671       }
1672       return first;
1673    }
1674 
1675    template <class RanIt, class K>
1676    RanIt priv_upper_bound
1677       (RanIt first, const RanIt last,const K & key) const
1678    {
1679       const Compare &key_cmp = this->m_data.get_comp();
1680       KeyOfValue key_extract;
1681       size_type len = static_cast<size_type>(last - first);
1682       RanIt middle;
1683 
1684       while (len) {
1685          size_type step = len >> 1;
1686          middle = first;
1687          middle += difference_type(step);
1688 
1689          if (key_cmp(key, key_extract(*middle))) {
1690             len = step;
1691          }
1692          else{
1693             first = ++middle;
1694             len -= step + 1;
1695          }
1696       }
1697       return first;
1698    }
1699 
1700    template <class RanIt, class K>
1701    std::pair<RanIt, RanIt>
1702       priv_equal_range(RanIt first, RanIt last, const K& key) const
1703    {
1704       const Compare &key_cmp = this->m_data.get_comp();
1705       KeyOfValue key_extract;
1706       size_type len = static_cast<size_type>(last - first);
1707       RanIt middle;
1708 
1709       while (len) {
1710          size_type step = len >> 1;
1711          middle = first;
1712          middle += difference_type(step);
1713 
1714          if (key_cmp(key_extract(*middle), key)){
1715             first = ++middle;
1716             len -= step + 1;
1717          }
1718          else if (key_cmp(key, key_extract(*middle))){
1719             len = step;
1720          }
1721          else {
1722             //Middle is equal to key
1723             last = first;
1724             last += difference_type(len);
1725             RanIt const first_ret = this->priv_lower_bound(first, middle, key);
1726             return std::pair<RanIt, RanIt>
1727                ( first_ret, this->priv_upper_bound(++middle, last, key));
1728          }
1729       }
1730       return std::pair<RanIt, RanIt>(first, first);
1731    }
1732 
1733    template<class RanIt, class K>
1734    std::pair<RanIt, RanIt> priv_lower_bound_range(RanIt first, RanIt last, const K& k) const
1735    {
1736       const Compare &key_cmp = this->m_data.get_comp();
1737       KeyOfValue key_extract;
1738       RanIt lb(this->priv_lower_bound(first, last, k)), ub(lb);
1739       if(lb != last && !key_cmp(k, key_extract(*lb))){
1740          ++ub;
1741       }
1742       return std::pair<RanIt, RanIt>(lb, ub);
1743    }
1744 };
1745 
1746 }  //namespace dtl {
1747 
1748 }  //namespace container {
1749 
1750 //!has_trivial_destructor_after_move<> == true_type
1751 //!specialization for optimizations
1752 template <class T, class KeyOfValue,
1753 class Compare, class AllocatorOrContainer>
1754 struct has_trivial_destructor_after_move<boost::container::dtl::flat_tree<T, KeyOfValue, Compare, AllocatorOrContainer> >
1755 {
1756    typedef boost::container::dtl::flat_tree<T, KeyOfValue, Compare, AllocatorOrContainer> flat_tree;
1757    typedef typename flat_tree::container_type container_type;
1758    typedef typename flat_tree::key_compare key_compare;
1759    BOOST_STATIC_CONSTEXPR bool value = ::boost::has_trivial_destructor_after_move<container_type>::value &&
1760                              ::boost::has_trivial_destructor_after_move<key_compare>::value;
1761 };
1762 
1763 }  //namespace boost {
1764 
1765 #include <boost/container/detail/config_end.hpp>
1766 
1767 #endif // BOOST_CONTAINER_FLAT_TREE_HPP