1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2007-2014
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 //
13 // The option that yields to non-floating point 1/sqrt(2) alpha is taken
14 // from the scapegoat tree implementation of the PSPP library.
15 //
16 /////////////////////////////////////////////////////////////////////////////
17 
18 #ifndef BOOST_INTRUSIVE_SGTREE_HPP
19 #define BOOST_INTRUSIVE_SGTREE_HPP
20 
21 #include <boost/intrusive/detail/config_begin.hpp>
22 #include <boost/intrusive/intrusive_fwd.hpp>
23 #include <boost/intrusive/detail/assert.hpp>
24 #include <boost/static_assert.hpp>
25 #include <boost/intrusive/bs_set_hook.hpp>
26 #include <boost/intrusive/bstree.hpp>
27 #include <boost/intrusive/detail/tree_node.hpp>
28 #include <boost/intrusive/pointer_traits.hpp>
29 #include <boost/intrusive/detail/mpl.hpp>
30 #include <boost/intrusive/detail/math.hpp>
31 #include <boost/intrusive/detail/get_value_traits.hpp>
32 #include <boost/intrusive/sgtree_algorithms.hpp>
33 #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
34 #include <boost/intrusive/link_mode.hpp>
35 
36 #include <boost/move/utility_core.hpp>
37 #include <boost/move/adl_move_swap.hpp>
38 
39 #include <cstddef>
40 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>
41 #include <boost/intrusive/detail/minimal_pair_header.hpp>   //std::pair
42 #include <cstddef>
43 
44 #if defined(BOOST_HAS_PRAGMA_ONCE)
45 #  pragma once
46 #endif
47 
48 namespace boost {
49 namespace intrusive {
50 
51 /// @cond
52 
53 namespace detail{
54 
55 /////////////////////////////////////////////////////////////
56 //
57 //       Halpha for fixed floating_point<false> option
58 //
59 /////////////////////////////////////////////////////////////
60 
61 //! Returns floor(log2(n)/log2(sqrt(2))) -> floor(2*log2(n))
62 //! Undefined if N is 0.
63 //!
64 //! This function does not use float point operations.
calculate_h_sqrt2(std::size_t n)65 inline std::size_t calculate_h_sqrt2 (std::size_t n)
66 {
67    std::size_t f_log2 = detail::floor_log2(n);
68    return (2*f_log2) + static_cast<std::size_t>(n >= detail::sqrt2_pow_2xplus1(f_log2));
69 }
70 
71 struct h_alpha_sqrt2_t
72 {
h_alpha_sqrt2_tboost::intrusive::detail::h_alpha_sqrt2_t73    h_alpha_sqrt2_t(void){}
operator ()boost::intrusive::detail::h_alpha_sqrt2_t74    std::size_t operator()(std::size_t n) const
75    {  return calculate_h_sqrt2(n);  }
76 };
77 
78 struct alpha_0_75_by_max_size_t
79 {
alpha_0_75_by_max_size_tboost::intrusive::detail::alpha_0_75_by_max_size_t80    alpha_0_75_by_max_size_t(void){}
81 
operator ()boost::intrusive::detail::alpha_0_75_by_max_size_t82    std::size_t operator()(std::size_t max_tree_size) const
83    {
84       const std::size_t max_tree_size_limit = ((~std::size_t(0))/std::size_t(3));
85       return max_tree_size > max_tree_size_limit ? max_tree_size/4*3 : max_tree_size*3/4;
86    }
87 };
88 
89 /////////////////////////////////////////////////////////////
90 //
91 //       Halpha for fixed floating_point<true> option
92 //
93 /////////////////////////////////////////////////////////////
94 
95 struct h_alpha_t
96 {
h_alpha_tboost::intrusive::detail::h_alpha_t97    explicit h_alpha_t(float inv_minus_logalpha)
98       :  inv_minus_logalpha_(inv_minus_logalpha)
99    {}
100 
operator ()boost::intrusive::detail::h_alpha_t101    std::size_t operator()(std::size_t n) const
102    {
103       ////////////////////////////////////////////////////////////
104       // This function must return "floor(log2(1/alpha(n)))" ->
105       //    floor(log2(n)/log(1/alpha)) ->
106       //    floor(log2(n)/-log2(alpha))
107       //    floor(log2(n)*(1/-log2(alpha)))
108       ////////////////////////////////////////////////////////////
109       return static_cast<std::size_t>(detail::fast_log2(float(n))*inv_minus_logalpha_);
110    }
111 
112    private:
113    //Since the function will be repeatedly called
114    //precalculate constant data to avoid repeated
115    //calls to log and division.
116    //This will store 1/(-std::log2(alpha_))
117    float inv_minus_logalpha_;
118 };
119 
120 struct alpha_by_max_size_t
121 {
alpha_by_max_size_tboost::intrusive::detail::alpha_by_max_size_t122    explicit alpha_by_max_size_t(float alpha)
123       :  alpha_(alpha)
124    {}
125 
operator ()boost::intrusive::detail::alpha_by_max_size_t126    float operator()(std::size_t max_tree_size) const
127    {  return float(max_tree_size)*alpha_;   }
128 
129    private:
130    float alpha_;
131 };
132 
133 template<bool Activate, class SizeType>
134 struct alpha_holder
135 {
136    typedef boost::intrusive::detail::h_alpha_t           h_alpha_t;
137    typedef boost::intrusive::detail::alpha_by_max_size_t multiply_by_alpha_t;
138 
alpha_holderboost::intrusive::detail::alpha_holder139    alpha_holder()
140       : max_tree_size_()
141    {  set_alpha(0.70711f);   } // ~1/sqrt(2)
142 
get_alphaboost::intrusive::detail::alpha_holder143    float get_alpha() const
144    {  return alpha_;  }
145 
set_alphaboost::intrusive::detail::alpha_holder146    void set_alpha(float alpha)
147    {
148       alpha_ = alpha;
149       inv_minus_logalpha_ = 1/(-detail::fast_log2(alpha));
150    }
151 
get_h_alpha_tboost::intrusive::detail::alpha_holder152    h_alpha_t get_h_alpha_t() const
153    {  return h_alpha_t(inv_minus_logalpha_);  }
154 
get_multiply_by_alpha_tboost::intrusive::detail::alpha_holder155    multiply_by_alpha_t get_multiply_by_alpha_t() const
156    {  return multiply_by_alpha_t(alpha_);  }
157 
get_max_tree_sizeboost::intrusive::detail::alpha_holder158    SizeType &get_max_tree_size()
159    {  return max_tree_size_;  }
160 
161    protected:
162    float alpha_;
163    float inv_minus_logalpha_;
164    SizeType max_tree_size_;
165 };
166 
167 template<class SizeType>
168 struct alpha_holder<false, SizeType>
169 {
170    //This specialization uses alpha = 1/sqrt(2)
171    //without using floating point operations
172    //Downside: alpha CAN't be changed.
173    typedef boost::intrusive::detail::h_alpha_sqrt2_t           h_alpha_t;
174    typedef boost::intrusive::detail::alpha_0_75_by_max_size_t  multiply_by_alpha_t;
175 
alpha_holderboost::intrusive::detail::alpha_holder176    alpha_holder()
177       : max_tree_size_()
178    {}
179 
get_alphaboost::intrusive::detail::alpha_holder180    float get_alpha() const
181    {  return 0.70710677f;  }
182 
set_alphaboost::intrusive::detail::alpha_holder183    void set_alpha(float)
184    {  //alpha CAN't be changed.
185       BOOST_INTRUSIVE_INVARIANT_ASSERT(0);
186    }
187 
get_h_alpha_tboost::intrusive::detail::alpha_holder188    h_alpha_t get_h_alpha_t() const
189    {  return h_alpha_t();  }
190 
get_multiply_by_alpha_tboost::intrusive::detail::alpha_holder191    multiply_by_alpha_t get_multiply_by_alpha_t() const
192    {  return multiply_by_alpha_t();  }
193 
get_max_tree_sizeboost::intrusive::detail::alpha_holder194    SizeType &get_max_tree_size()
195    {  return max_tree_size_;  }
196 
197    protected:
198    SizeType max_tree_size_;
199 };
200 
201 }  //namespace detail{
202 
203 struct sgtree_defaults
204    : bstree_defaults
205 {
206    static const bool floating_point = true;
207 };
208 
209 /// @endcond
210 
211 //! The class template sgtree is an intrusive scapegoat tree container, that
212 //! is used to construct intrusive sg_set and sg_multiset containers.
213 //! The no-throw guarantee holds only, if the value_compare object
214 //! doesn't throw.
215 //!
216 //! The template parameter \c T is the type to be managed by the container.
217 //! The user can specify additional options and if no options are provided
218 //! default options are used.
219 //!
220 //! The container supports the following options:
221 //! \c base_hook<>/member_hook<>/value_traits<>,
222 //! \c floating_point<>, \c size_type<> and
223 //! \c compare<>.
224 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
225 template<class T, class ...Options>
226 #else
227 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, bool FloatingPoint, typename HeaderHolder>
228 #endif
229 class sgtree_impl
230    /// @cond
231    :  public bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType, true, SgTreeAlgorithms, HeaderHolder>
232    ,  public detail::alpha_holder<FloatingPoint, SizeType>
233    /// @endcond
234 {
235    public:
236    typedef ValueTraits                                               value_traits;
237    /// @cond
238    typedef bstree_impl< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType
239                       , true, SgTreeAlgorithms, HeaderHolder>        tree_type;
240    typedef tree_type                                                 implementation_defined;
241 
242    /// @endcond
243 
244    typedef typename implementation_defined::pointer                  pointer;
245    typedef typename implementation_defined::const_pointer            const_pointer;
246    typedef typename implementation_defined::value_type               value_type;
247    typedef typename implementation_defined::key_type                 key_type;
248    typedef typename implementation_defined::key_of_value             key_of_value;
249    typedef typename implementation_defined::reference                reference;
250    typedef typename implementation_defined::const_reference          const_reference;
251    typedef typename implementation_defined::difference_type          difference_type;
252    typedef typename implementation_defined::size_type                size_type;
253    typedef typename implementation_defined::value_compare            value_compare;
254    typedef typename implementation_defined::key_compare              key_compare;
255    typedef typename implementation_defined::iterator                 iterator;
256    typedef typename implementation_defined::const_iterator           const_iterator;
257    typedef typename implementation_defined::reverse_iterator         reverse_iterator;
258    typedef typename implementation_defined::const_reverse_iterator   const_reverse_iterator;
259    typedef typename implementation_defined::node_traits              node_traits;
260    typedef typename implementation_defined::node                     node;
261    typedef typename implementation_defined::node_ptr                 node_ptr;
262    typedef typename implementation_defined::const_node_ptr           const_node_ptr;
263    typedef BOOST_INTRUSIVE_IMPDEF(sgtree_algorithms<node_traits>)    node_algorithms;
264 
265    static const bool constant_time_size      = implementation_defined::constant_time_size;
266    static const bool floating_point          = FloatingPoint;
267    static const bool stateful_value_traits   = implementation_defined::stateful_value_traits;
268 
269    /// @cond
270    private:
271 
272    //noncopyable
273    typedef detail::alpha_holder<FloatingPoint, SizeType>    alpha_traits;
274    typedef typename alpha_traits::h_alpha_t                 h_alpha_t;
275    typedef typename alpha_traits::multiply_by_alpha_t       multiply_by_alpha_t;
276 
277    BOOST_MOVABLE_BUT_NOT_COPYABLE(sgtree_impl)
278    BOOST_STATIC_ASSERT(((int)value_traits::link_mode != (int)auto_unlink));
279 
280    enum { safemode_or_autounlink  =
281             (int)value_traits::link_mode == (int)auto_unlink   ||
282             (int)value_traits::link_mode == (int)safe_link     };
283 
284    /// @endcond
285 
286    public:
287 
288    typedef BOOST_INTRUSIVE_IMPDEF(typename node_algorithms::insert_commit_data) insert_commit_data;
289 
290    //! @copydoc ::boost::intrusive::bstree::bstree()
sgtree_impl()291    sgtree_impl()
292       :  tree_type()
293    {}
294 
295    //! @copydoc ::boost::intrusive::bstree::bstree(const key_compare &,const value_traits &)
sgtree_impl(const key_compare & cmp,const value_traits & v_traits=value_traits ())296    explicit sgtree_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
297       :  tree_type(cmp, v_traits)
298    {}
299 
300    //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const key_compare &,const value_traits &)
301    template<class Iterator>
sgtree_impl(bool unique,Iterator b,Iterator e,const key_compare & cmp=key_compare (),const value_traits & v_traits=value_traits ())302    sgtree_impl( bool unique, Iterator b, Iterator e
303               , const key_compare &cmp     = key_compare()
304               , const value_traits &v_traits = value_traits())
305       : tree_type(cmp, v_traits)
306    {
307       if(unique)
308          this->insert_unique(b, e);
309       else
310          this->insert_equal(b, e);
311    }
312 
313    //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
sgtree_impl(BOOST_RV_REF (sgtree_impl)x)314    sgtree_impl(BOOST_RV_REF(sgtree_impl) x)
315       :  tree_type(BOOST_MOVE_BASE(tree_type, x)), alpha_traits(x.get_alpha_traits())
316    {  ::boost::adl_move_swap(this->get_alpha_traits(), x.get_alpha_traits());   }
317 
318    //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
operator =(BOOST_RV_REF (sgtree_impl)x)319    sgtree_impl& operator=(BOOST_RV_REF(sgtree_impl) x)
320    {
321       this->get_alpha_traits() = x.get_alpha_traits();
322       return static_cast<sgtree_impl&>(tree_type::operator=(BOOST_MOVE_BASE(tree_type, x)));
323    }
324 
325    /// @cond
326    private:
327 
get_alpha_traits() const328    const alpha_traits &get_alpha_traits() const
329    {  return *this;  }
330 
get_alpha_traits()331    alpha_traits &get_alpha_traits()
332    {  return *this;  }
333 
get_h_alpha_func() const334    h_alpha_t get_h_alpha_func() const
335    {  return this->get_alpha_traits().get_h_alpha_t();  }
336 
get_alpha_by_max_size_func() const337    multiply_by_alpha_t get_alpha_by_max_size_func() const
338    {  return this->get_alpha_traits().get_multiply_by_alpha_t(); }
339 
340    /// @endcond
341 
342    public:
343 
344    #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
345    //! @copydoc ::boost::intrusive::bstree::~bstree()
346    ~sgtree_impl();
347 
348    //! @copydoc ::boost::intrusive::bstree::begin()
349    iterator begin();
350 
351    //! @copydoc ::boost::intrusive::bstree::begin()const
352    const_iterator begin() const;
353 
354    //! @copydoc ::boost::intrusive::bstree::cbegin()const
355    const_iterator cbegin() const;
356 
357    //! @copydoc ::boost::intrusive::bstree::end()
358    iterator end();
359 
360    //! @copydoc ::boost::intrusive::bstree::end()const
361    const_iterator end() const;
362 
363    //! @copydoc ::boost::intrusive::bstree::cend()const
364    const_iterator cend() const;
365 
366    //! @copydoc ::boost::intrusive::bstree::rbegin()
367    reverse_iterator rbegin();
368 
369    //! @copydoc ::boost::intrusive::bstree::rbegin()const
370    const_reverse_iterator rbegin() const;
371 
372    //! @copydoc ::boost::intrusive::bstree::crbegin()const
373    const_reverse_iterator crbegin() const;
374 
375    //! @copydoc ::boost::intrusive::bstree::rend()
376    reverse_iterator rend();
377 
378    //! @copydoc ::boost::intrusive::bstree::rend()const
379    const_reverse_iterator rend() const;
380 
381    //! @copydoc ::boost::intrusive::bstree::crend()const
382    const_reverse_iterator crend() const;
383 
384    //! @copydoc ::boost::intrusive::bstree::root()
385    iterator root();
386 
387    //! @copydoc ::boost::intrusive::bstree::root()const
388    const_iterator root() const;
389 
390    //! @copydoc ::boost::intrusive::bstree::croot()const
391    const_iterator croot() const;
392 
393    //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
394    static sgtree_impl &container_from_end_iterator(iterator end_iterator);
395 
396    //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
397    static const sgtree_impl &container_from_end_iterator(const_iterator end_iterator);
398 
399    //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
400    static sgtree_impl &container_from_iterator(iterator it);
401 
402    //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
403    static const sgtree_impl &container_from_iterator(const_iterator it);
404 
405    //! @copydoc ::boost::intrusive::bstree::key_comp()const
406    key_compare key_comp() const;
407 
408    //! @copydoc ::boost::intrusive::bstree::value_comp()const
409    value_compare value_comp() const;
410 
411    //! @copydoc ::boost::intrusive::bstree::empty()const
412    bool empty() const;
413 
414    //! @copydoc ::boost::intrusive::bstree::size()const
415    size_type size() const;
416 
417    #endif   //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
418 
419    //! @copydoc ::boost::intrusive::bstree::swap
swap(sgtree_impl & other)420    void swap(sgtree_impl& other)
421    {
422       //This can throw
423       this->tree_type::swap(static_cast<tree_type&>(other));
424       ::boost::adl_move_swap(this->get_alpha_traits(), other.get_alpha_traits());
425    }
426 
427    //! @copydoc ::boost::intrusive::bstree::clone_from(const bstree&,Cloner,Disposer)
428    //! Additional notes: it also copies the alpha factor from the source container.
429    template <class Cloner, class Disposer>
clone_from(const sgtree_impl & src,Cloner cloner,Disposer disposer)430    void clone_from(const sgtree_impl &src, Cloner cloner, Disposer disposer)
431    {
432       tree_type::clone_from(src, cloner, disposer);
433       this->get_alpha_traits() = src.get_alpha_traits();
434    }
435 
436    //! @copydoc ::boost::intrusive::bstree::clone_from(bstree&&,Cloner,Disposer)
437    //! Additional notes: it also copies the alpha factor from the source container.
438    template <class Cloner, class Disposer>
clone_from(BOOST_RV_REF (sgtree_impl)src,Cloner cloner,Disposer disposer)439    void clone_from(BOOST_RV_REF(sgtree_impl) src, Cloner cloner, Disposer disposer)
440    {
441       tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer);
442       this->get_alpha_traits() = ::boost::move(src.get_alpha_traits());
443    }
444 
445    //! @copydoc ::boost::intrusive::bstree::insert_equal(reference)
insert_equal(reference value)446    iterator insert_equal(reference value)
447    {
448       node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
449       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
450       std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
451       node_ptr p = node_algorithms::insert_equal_upper_bound
452          (this->tree_type::header_ptr(), to_insert, this->key_node_comp(this->key_comp())
453          , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
454       this->tree_type::sz_traits().increment();
455       this->max_tree_size_ = (size_type)max_tree_size;
456       return iterator(p, this->priv_value_traits_ptr());
457    }
458 
459    //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference)
insert_equal(const_iterator hint,reference value)460    iterator insert_equal(const_iterator hint, reference value)
461    {
462       node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
463       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
464       std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
465       node_ptr p = node_algorithms::insert_equal
466          ( this->tree_type::header_ptr(), hint.pointed_node(), to_insert, this->key_node_comp(this->key_comp())
467          , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size);
468       this->tree_type::sz_traits().increment();
469       this->max_tree_size_ = (size_type)max_tree_size;
470       return iterator(p, this->priv_value_traits_ptr());
471    }
472 
473    //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator)
474    template<class Iterator>
insert_equal(Iterator b,Iterator e)475    void insert_equal(Iterator b, Iterator e)
476    {
477       iterator iend(this->end());
478       for (; b != e; ++b)
479          this->insert_equal(iend, *b);
480    }
481 
482    //! @copydoc ::boost::intrusive::bstree::insert_unique(reference)
insert_unique(reference value)483    std::pair<iterator, bool> insert_unique(reference value)
484    {
485       insert_commit_data commit_data;
486       std::pair<iterator, bool> ret = this->insert_unique_check
487          (key_of_value()(value), this->key_comp(), commit_data);
488       if(!ret.second)
489          return ret;
490       return std::pair<iterator, bool> (this->insert_unique_commit(value, commit_data), true);
491    }
492 
493    //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference)
insert_unique(const_iterator hint,reference value)494    iterator insert_unique(const_iterator hint, reference value)
495    {
496       insert_commit_data commit_data;
497       std::pair<iterator, bool> ret = this->insert_unique_check
498          (hint, key_of_value()(value), this->key_comp(), commit_data);
499       if(!ret.second)
500          return ret.first;
501       return this->insert_unique_commit(value, commit_data);
502    }
503 
504    //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
505    template<class KeyType, class KeyTypeKeyCompare>
BOOST_INTRUSIVE_DOC1ST(std::pair<iterator BOOST_INTRUSIVE_I bool>,typename detail::disable_if_convertible<KeyType BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I std::pair<iterator BOOST_INTRUSIVE_I bool>>::type)506    BOOST_INTRUSIVE_DOC1ST(std::pair<iterator BOOST_INTRUSIVE_I bool>
507       , typename detail::disable_if_convertible
508          <KeyType BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I
509          std::pair<iterator BOOST_INTRUSIVE_I bool> >::type)
510       insert_unique_check
511       (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data)
512    {
513       std::pair<node_ptr, bool> ret =
514          node_algorithms::insert_unique_check
515             (this->tree_type::header_ptr(), key, this->key_node_comp(comp), commit_data);
516       return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
517    }
518 
519    //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
520    template<class KeyType, class KeyTypeKeyCompare>
insert_unique_check(const_iterator hint,const KeyType & key,KeyTypeKeyCompare comp,insert_commit_data & commit_data)521    std::pair<iterator, bool> insert_unique_check
522       (const_iterator hint, const KeyType &key
523       ,KeyTypeKeyCompare comp, insert_commit_data &commit_data)
524    {
525       std::pair<node_ptr, bool> ret =
526          node_algorithms::insert_unique_check
527             (this->tree_type::header_ptr(), hint.pointed_node(), key, this->key_node_comp(comp), commit_data);
528       return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
529    }
530 
531    //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const key_type&,insert_commit_data&)
insert_unique_check(const key_type & key,insert_commit_data & commit_data)532    std::pair<iterator, bool> insert_unique_check
533       (const key_type &key, insert_commit_data &commit_data)
534    {  return this->insert_unique_check(key, this->key_comp(), commit_data);   }
535 
536    //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const key_type&,insert_commit_data&)
insert_unique_check(const_iterator hint,const key_type & key,insert_commit_data & commit_data)537    std::pair<iterator, bool> insert_unique_check
538       (const_iterator hint, const key_type &key, insert_commit_data &commit_data)
539    {  return this->insert_unique_check(hint, key, this->key_comp(), commit_data);   }
540 
541    //! @copydoc ::boost::intrusive::bstree::insert_unique_commit
insert_unique_commit(reference value,const insert_commit_data & commit_data)542    iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
543    {
544       node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
545       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
546       std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
547       node_algorithms::insert_unique_commit
548          ( this->tree_type::header_ptr(), to_insert, commit_data
549          , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size);
550       this->tree_type::sz_traits().increment();
551       this->max_tree_size_ = (size_type)max_tree_size;
552       return iterator(to_insert, this->priv_value_traits_ptr());
553    }
554 
555    //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator)
556    template<class Iterator>
insert_unique(Iterator b,Iterator e)557    void insert_unique(Iterator b, Iterator e)
558    {
559       if(this->empty()){
560          iterator iend(this->end());
561          for (; b != e; ++b)
562             this->insert_unique(iend, *b);
563       }
564       else{
565          for (; b != e; ++b)
566             this->insert_unique(*b);
567       }
568    }
569 
570    //! @copydoc ::boost::intrusive::bstree::insert_before
insert_before(const_iterator pos,reference value)571    iterator insert_before(const_iterator pos, reference value)
572    {
573       node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
574       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
575       std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
576       node_ptr p = node_algorithms::insert_before
577          ( this->tree_type::header_ptr(), pos.pointed_node(), to_insert
578          , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
579       this->tree_type::sz_traits().increment();
580       this->max_tree_size_ = (size_type)max_tree_size;
581       return iterator(p, this->priv_value_traits_ptr());
582    }
583 
584    //! @copydoc ::boost::intrusive::bstree::push_back
push_back(reference value)585    void push_back(reference value)
586    {
587       node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
588       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
589       std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
590       node_algorithms::push_back
591          ( this->tree_type::header_ptr(), to_insert
592          , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
593       this->tree_type::sz_traits().increment();
594       this->max_tree_size_ = (size_type)max_tree_size;
595    }
596 
597    //! @copydoc ::boost::intrusive::bstree::push_front
push_front(reference value)598    void push_front(reference value)
599    {
600       node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
601       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
602       std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
603       node_algorithms::push_front
604          ( this->tree_type::header_ptr(), to_insert
605          , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
606       this->tree_type::sz_traits().increment();
607       this->max_tree_size_ = (size_type)max_tree_size;
608    }
609 
610 
611    //! @copydoc ::boost::intrusive::bstree::erase(const_iterator)
erase(const_iterator i)612    iterator erase(const_iterator i)
613    {
614       const_iterator ret(i);
615       ++ret;
616       node_ptr to_erase(i.pointed_node());
617       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(to_erase));
618       std::size_t max_tree_size = this->max_tree_size_;
619       node_algorithms::erase
620          ( this->tree_type::header_ptr(), to_erase, (std::size_t)this->size()
621          , max_tree_size, this->get_alpha_by_max_size_func());
622       this->max_tree_size_ = (size_type)max_tree_size;
623       this->tree_type::sz_traits().decrement();
624       if(safemode_or_autounlink)
625          node_algorithms::init(to_erase);
626       return ret.unconst();
627    }
628 
629    //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator)
erase(const_iterator b,const_iterator e)630    iterator erase(const_iterator b, const_iterator e)
631    {  size_type n;   return private_erase(b, e, n);   }
632 
633    //! @copydoc ::boost::intrusive::bstree::erase(const key_type &)
erase(const key_type & key)634    size_type erase(const key_type &key)
635    {  return this->erase(key, this->key_comp());   }
636 
637    //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyTypeKeyCompare)
638    template<class KeyType, class KeyTypeKeyCompare>
BOOST_INTRUSIVE_DOC1ST(size_type,typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)639    BOOST_INTRUSIVE_DOC1ST(size_type
640       , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
641       erase(const KeyType& key, KeyTypeKeyCompare comp)
642    {
643       std::pair<iterator,iterator> p = this->equal_range(key, comp);
644       size_type n;
645       private_erase(p.first, p.second, n);
646       return n;
647    }
648 
649    //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer)
650    template<class Disposer>
erase_and_dispose(const_iterator i,Disposer disposer)651    iterator erase_and_dispose(const_iterator i, Disposer disposer)
652    {
653       node_ptr to_erase(i.pointed_node());
654       iterator ret(this->erase(i));
655       disposer(this->get_value_traits().to_value_ptr(to_erase));
656       return ret;
657    }
658 
659    #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
660    template<class Disposer>
erase_and_dispose(iterator i,Disposer disposer)661    iterator erase_and_dispose(iterator i, Disposer disposer)
662    {  return this->erase_and_dispose(const_iterator(i), disposer);   }
663    #endif
664 
665    //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer)
666    template<class Disposer>
erase_and_dispose(const_iterator b,const_iterator e,Disposer disposer)667    iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
668    {  size_type n;   return private_erase(b, e, n, disposer);   }
669 
670    //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const key_type &, Disposer)
671    template<class Disposer>
erase_and_dispose(const key_type & key,Disposer disposer)672    size_type erase_and_dispose(const key_type &key, Disposer disposer)
673    {
674       std::pair<iterator,iterator> p = this->equal_range(key);
675       size_type n;
676       private_erase(p.first, p.second, n, disposer);
677       return n;
678    }
679 
680    //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyTypeKeyCompare,Disposer)
681    template<class KeyType, class KeyTypeKeyCompare, class Disposer>
BOOST_INTRUSIVE_DOC1ST(size_type,typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)682    BOOST_INTRUSIVE_DOC1ST(size_type
683       , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
684       erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer)
685    {
686       std::pair<iterator,iterator> p = this->equal_range(key, comp);
687       size_type n;
688       private_erase(p.first, p.second, n, disposer);
689       return n;
690    }
691 
692    //! @copydoc ::boost::intrusive::bstree::clear
clear()693    void clear()
694    {
695       tree_type::clear();
696       this->max_tree_size_ = 0;
697    }
698 
699    //! @copydoc ::boost::intrusive::bstree::clear_and_dispose
700    template<class Disposer>
clear_and_dispose(Disposer disposer)701    void clear_and_dispose(Disposer disposer)
702    {
703       tree_type::clear_and_dispose(disposer);
704       this->max_tree_size_ = 0;
705    }
706 
707    #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
708    //! @copydoc ::boost::intrusive::bstree::merge_unique
709    template<class T, class ...Options2> void merge_unique(sgtree<T, Options2...> &);
710    #else
711    template<class Compare2>
merge_unique(sgtree_impl<ValueTraits,VoidOrKeyOfValue,Compare2,SizeType,FloatingPoint,HeaderHolder> & source)712    void merge_unique(sgtree_impl
713       <ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, FloatingPoint, HeaderHolder> &source)
714    #endif
715    {
716       node_ptr it   (node_algorithms::begin_node(source.header_ptr()))
717              , itend(node_algorithms::end_node  (source.header_ptr()));
718 
719       while(it != itend){
720          node_ptr const p(it);
721          BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(p));
722          it = node_algorithms::next_node(it);
723 
724          std::size_t max_tree1_size = this->max_tree_size_;
725          std::size_t max_tree2_size = source.get_max_tree_size();
726          if( node_algorithms::transfer_unique
727                ( this->header_ptr(), this->key_node_comp(this->key_comp()), this->size(), max_tree1_size
728                , source.header_ptr(), p, source.size(), max_tree2_size
729                , this->get_h_alpha_func(), this->get_alpha_by_max_size_func()) ){
730             this->max_tree_size_  = (size_type)max_tree1_size;
731             this->sz_traits().increment();
732             source.get_max_tree_size() = (size_type)max_tree2_size;
733             source.sz_traits().decrement();
734          }
735       }
736    }
737 
738    #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
739    //! @copydoc ::boost::intrusive::bstree::merge_equal
740    template<class T, class ...Options2> void merge_equal(sgtree<T, Options2...> &);
741    #else
742    template<class Compare2>
merge_equal(sgtree_impl<ValueTraits,VoidOrKeyOfValue,Compare2,SizeType,FloatingPoint,HeaderHolder> & source)743    void merge_equal(sgtree_impl
744       <ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, FloatingPoint, HeaderHolder> &source)
745    #endif
746    {
747       node_ptr it   (node_algorithms::begin_node(source.header_ptr()))
748              , itend(node_algorithms::end_node  (source.header_ptr()));
749 
750       while(it != itend){
751          node_ptr const p(it);
752          BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(p));
753          it = node_algorithms::next_node(it);
754          std::size_t max_tree1_size = this->max_tree_size_;
755          std::size_t max_tree2_size = source.get_max_tree_size();
756          node_algorithms::transfer_equal
757             ( this->header_ptr(), this->key_node_comp(this->key_comp()), this->size(), max_tree1_size
758             , source.header_ptr(), p, source.size(), max_tree2_size
759             , this->get_h_alpha_func(), this->get_alpha_by_max_size_func());
760          this->max_tree_size_  = (size_type)max_tree1_size;
761          this->sz_traits().increment();
762          source.get_max_tree_size() = (size_type)max_tree2_size;
763          source.sz_traits().decrement();
764       }
765    }
766 
767    #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
768    //! @copydoc ::boost::intrusive::bstree::count(const key_type &)const
769    size_type count(const key_type &key) const;
770 
771    //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyTypeKeyCompare)const
772    template<class KeyType, class KeyTypeKeyCompare>
773    size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
774 
775    //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)
776    iterator lower_bound(const key_type &key);
777 
778    //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)
779    template<class KeyType, class KeyTypeKeyCompare>
780    iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
781 
782    //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)const
783    const_iterator lower_bound(const key_type &key) const;
784 
785    //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)const
786    template<class KeyType, class KeyTypeKeyCompare>
787    const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
788 
789    //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)
790    iterator upper_bound(const key_type &key);
791 
792    //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)
793    template<class KeyType, class KeyTypeKeyCompare>
794    iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
795 
796    //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)const
797    const_iterator upper_bound(const key_type &key) const;
798 
799    //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)const
800    template<class KeyType, class KeyTypeKeyCompare>
801    const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
802 
803    //! @copydoc ::boost::intrusive::bstree::find(const key_type &)
804    iterator find(const key_type &key);
805 
806    //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)
807    template<class KeyType, class KeyTypeKeyCompare>
808    iterator find(const KeyType& key, KeyTypeKeyCompare comp);
809 
810    //! @copydoc ::boost::intrusive::bstree::find(const key_type &)const
811    const_iterator find(const key_type &key) const;
812 
813    //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)const
814    template<class KeyType, class KeyTypeKeyCompare>
815    const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
816 
817    //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)
818    std::pair<iterator,iterator> equal_range(const key_type &key);
819 
820    //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)
821    template<class KeyType, class KeyTypeKeyCompare>
822    std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
823 
824    //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)const
825    std::pair<const_iterator, const_iterator>
826       equal_range(const key_type &key) const;
827 
828    //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)const
829    template<class KeyType, class KeyTypeKeyCompare>
830    std::pair<const_iterator, const_iterator>
831       equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
832 
833    //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)
834    std::pair<iterator,iterator> bounded_range
835       (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed);
836 
837    //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
838    template<class KeyType, class KeyTypeKeyCompare>
839    std::pair<iterator,iterator> bounded_range
840       (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
841 
842    //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)const
843    std::pair<const_iterator, const_iterator>
844       bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
845 
846    //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)const
847    template<class KeyType, class KeyTypeKeyCompare>
848    std::pair<const_iterator, const_iterator> bounded_range
849          (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
850 
851    //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
852    static iterator s_iterator_to(reference value);
853 
854    //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
855    static const_iterator s_iterator_to(const_reference value);
856 
857    //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
858    iterator iterator_to(reference value);
859 
860    //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
861    const_iterator iterator_to(const_reference value) const;
862 
863    //! @copydoc ::boost::intrusive::bstree::init_node(reference)
864    static void init_node(reference value);
865 
866    //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
867    pointer unlink_leftmost_without_rebalance();
868 
869    //! @copydoc ::boost::intrusive::bstree::replace_node
870    void replace_node(iterator replace_this, reference with_this);
871 
872    //! @copydoc ::boost::intrusive::bstree::remove_node
873    void remove_node(reference value);
874 
875    //! @copydoc ::boost::intrusive::bstree::rebalance
876    void rebalance();
877 
878    //! @copydoc ::boost::intrusive::bstree::rebalance_subtree
879    iterator rebalance_subtree(iterator root);
880 
881    friend bool operator< (const sgtree_impl &x, const sgtree_impl &y);
882 
883    friend bool operator==(const sgtree_impl &x, const sgtree_impl &y);
884 
885    friend bool operator!= (const sgtree_impl &x, const sgtree_impl &y);
886 
887    friend bool operator>(const sgtree_impl &x, const sgtree_impl &y);
888 
889    friend bool operator<=(const sgtree_impl &x, const sgtree_impl &y);
890 
891    friend bool operator>=(const sgtree_impl &x, const sgtree_impl &y);
892 
893    friend void swap(sgtree_impl &x, sgtree_impl &y);
894 
895    #endif   //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
896 
897    //! <b>Returns</b>: The balance factor (alpha) used in this tree
898    //!
899    //! <b>Throws</b>: Nothing.
900    //!
901    //! <b>Complexity</b>: Constant.
balance_factor() const902    float balance_factor() const
903    {  return this->get_alpha_traits().get_alpha(); }
904 
905    //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
906    //!
907    //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
908    //!   the tree if the new balance factor is stricter (less) than the old factor.
909    //!
910    //! <b>Throws</b>: Nothing.
911    //!
912    //! <b>Complexity</b>: Linear to the elements in the subtree.
balance_factor(float new_alpha)913    void balance_factor(float new_alpha)
914    {
915       //The alpha factor CAN't be changed if the fixed, floating operation-less
916       //1/sqrt(2) alpha factor option is activated
917       BOOST_STATIC_ASSERT((floating_point));
918       BOOST_INTRUSIVE_INVARIANT_ASSERT((new_alpha > 0.5f && new_alpha < 1.0f));
919       if(new_alpha >= 0.5f && new_alpha < 1.0f){
920          float old_alpha = this->get_alpha_traits().get_alpha();
921          this->get_alpha_traits().set_alpha(new_alpha);
922          if(new_alpha < old_alpha){
923             this->max_tree_size_ = this->size();
924             this->rebalance();
925          }
926       }
927    }
928 
929    /// @cond
930    private:
931    template<class Disposer>
private_erase(const_iterator b,const_iterator e,size_type & n,Disposer disposer)932    iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
933    {
934       for(n = 0; b != e; ++n)
935         this->erase_and_dispose(b++, disposer);
936       return b.unconst();
937    }
938 
private_erase(const_iterator b,const_iterator e,size_type & n)939    iterator private_erase(const_iterator b, const_iterator e, size_type &n)
940    {
941       for(n = 0; b != e; ++n)
942         this->erase(b++);
943       return b.unconst();
944    }
945    /// @endcond
946 };
947 
948 
949 //! Helper metafunction to define a \c sgtree that yields to the same type when the
950 //! same options (either explicitly or implicitly) are used.
951 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
952 template<class T, class ...Options>
953 #else
954 template<class T, class O1 = void, class O2 = void
955                 , class O3 = void, class O4 = void
956                 , class O5 = void, class O6 = void>
957 #endif
958 struct make_sgtree
959 {
960    /// @cond
961    typedef typename pack_options
962       < sgtree_defaults,
963       #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
964       O1, O2, O3, O4, O5, O6
965       #else
966       Options...
967       #endif
968       >::type packed_options;
969 
970    typedef typename detail::get_value_traits
971       <T, typename packed_options::proto_value_traits>::type value_traits;
972 
973    typedef sgtree_impl
974          < value_traits
975          , typename packed_options::key_of_value
976          , typename packed_options::compare
977          , typename packed_options::size_type
978          , packed_options::floating_point
979          , typename packed_options::header_holder_type
980          > implementation_defined;
981    /// @endcond
982    typedef implementation_defined type;
983 };
984 
985 
986 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
987 
988 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
989 template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
990 #else
991 template<class T, class ...Options>
992 #endif
993 class sgtree
994    :  public make_sgtree<T,
995       #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
996       O1, O2, O3, O4, O5, O6
997       #else
998       Options...
999       #endif
1000       >::type
1001 {
1002    typedef typename make_sgtree
1003       <T,
1004       #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1005       O1, O2, O3, O4, O5, O6
1006       #else
1007       Options...
1008       #endif
1009       >::type   Base;
1010    BOOST_MOVABLE_BUT_NOT_COPYABLE(sgtree)
1011 
1012    public:
1013    typedef typename Base::key_compare        key_compare;
1014    typedef typename Base::value_traits       value_traits;
1015    typedef typename Base::iterator           iterator;
1016    typedef typename Base::const_iterator     const_iterator;
1017    typedef typename Base::reverse_iterator           reverse_iterator;
1018    typedef typename Base::const_reverse_iterator     const_reverse_iterator;
1019 
1020    //Assert if passed value traits are compatible with the type
1021    BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
1022 
sgtree()1023    BOOST_INTRUSIVE_FORCEINLINE sgtree()
1024       :  Base()
1025    {}
1026 
sgtree(const key_compare & cmp,const value_traits & v_traits=value_traits ())1027    BOOST_INTRUSIVE_FORCEINLINE explicit sgtree(const key_compare &cmp, const value_traits &v_traits = value_traits())
1028       :  Base(cmp, v_traits)
1029    {}
1030 
1031    template<class Iterator>
sgtree(bool unique,Iterator b,Iterator e,const key_compare & cmp=key_compare (),const value_traits & v_traits=value_traits ())1032    BOOST_INTRUSIVE_FORCEINLINE sgtree( bool unique, Iterator b, Iterator e
1033          , const key_compare &cmp = key_compare()
1034          , const value_traits &v_traits = value_traits())
1035       :  Base(unique, b, e, cmp, v_traits)
1036    {}
1037 
sgtree(BOOST_RV_REF (sgtree)x)1038    BOOST_INTRUSIVE_FORCEINLINE sgtree(BOOST_RV_REF(sgtree) x)
1039       :  Base(BOOST_MOVE_BASE(Base, x))
1040    {}
1041 
operator =(BOOST_RV_REF (sgtree)x)1042    BOOST_INTRUSIVE_FORCEINLINE sgtree& operator=(BOOST_RV_REF(sgtree) x)
1043    {  return static_cast<sgtree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x)));  }
1044 
1045    template <class Cloner, class Disposer>
clone_from(const sgtree & src,Cloner cloner,Disposer disposer)1046    BOOST_INTRUSIVE_FORCEINLINE void clone_from(const sgtree &src, Cloner cloner, Disposer disposer)
1047    {  Base::clone_from(src, cloner, disposer);  }
1048 
1049    template <class Cloner, class Disposer>
clone_from(BOOST_RV_REF (sgtree)src,Cloner cloner,Disposer disposer)1050    BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(sgtree) src, Cloner cloner, Disposer disposer)
1051    {  Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer);  }
1052 
container_from_end_iterator(iterator end_iterator)1053    BOOST_INTRUSIVE_FORCEINLINE static sgtree &container_from_end_iterator(iterator end_iterator)
1054    {  return static_cast<sgtree &>(Base::container_from_end_iterator(end_iterator));   }
1055 
container_from_end_iterator(const_iterator end_iterator)1056    BOOST_INTRUSIVE_FORCEINLINE static const sgtree &container_from_end_iterator(const_iterator end_iterator)
1057    {  return static_cast<const sgtree &>(Base::container_from_end_iterator(end_iterator));   }
1058 
container_from_iterator(iterator it)1059    BOOST_INTRUSIVE_FORCEINLINE static sgtree &container_from_iterator(iterator it)
1060    {  return static_cast<sgtree &>(Base::container_from_iterator(it));   }
1061 
container_from_iterator(const_iterator it)1062    BOOST_INTRUSIVE_FORCEINLINE static const sgtree &container_from_iterator(const_iterator it)
1063    {  return static_cast<const sgtree &>(Base::container_from_iterator(it));   }
1064 };
1065 
1066 #endif
1067 
1068 } //namespace intrusive
1069 } //namespace boost
1070 
1071 #include <boost/intrusive/detail/config_end.hpp>
1072 
1073 #endif //BOOST_INTRUSIVE_SGTREE_HPP
1074