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