ext-boost/boost/intrusive/detail/tree_value_compare.hpp

187 lines
7.5 KiB
C++
Raw Normal View History

2016-03-02 05:27:27 +00:00
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
#define BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
2017-03-13 04:29:07 +00:00
#include <boost/intrusive/detail/workaround.hpp>
2016-03-02 05:27:27 +00:00
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/ebo_functor_holder.hpp>
2017-03-13 04:29:07 +00:00
#include <boost/intrusive/pointer_traits.hpp>
2016-03-02 05:27:27 +00:00
namespace boost{
namespace intrusive{
2017-03-13 04:29:07 +00:00
//Needed to support smart references to value types
template <class From, class ValuePtr>
struct disable_if_smartref_to
: detail::disable_if_c
< detail::is_same
<From, typename pointer_traits
<ValuePtr>
::reference>::value
|| detail::is_same
<From, typename pointer_traits
< typename pointer_rebind
2018-01-01 20:31:13 +00:00
< ValuePtr
, const typename boost::movelib::pointer_element<ValuePtr>::type>::type>
2017-03-13 04:29:07 +00:00
::reference>::value
>
{};
//This function object takes a KeyCompare function object
//and compares values that contains keys using KeyOfValue
2019-08-24 13:39:04 +00:00
template< class ValuePtr, class KeyCompare, class KeyOfValue, class Ret = bool
2018-01-01 20:31:13 +00:00
, bool = boost::intrusive::detail::is_same
<typename boost::movelib::pointer_element<ValuePtr>::type, typename KeyOfValue::type>::value >
2016-03-02 05:27:27 +00:00
struct tree_value_compare
: public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
{
2018-01-01 20:31:13 +00:00
typedef typename
boost::movelib::pointer_element<ValuePtr>::type value_type;
2017-03-13 04:29:07 +00:00
typedef KeyCompare key_compare;
typedef KeyOfValue key_of_value;
typedef typename KeyOfValue::type key_type;
2016-03-02 05:27:27 +00:00
typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
2017-03-13 04:29:07 +00:00
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
: base_t()
{}
BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
2016-03-02 05:27:27 +00:00
: base_t(kcomp)
{}
2017-03-13 04:29:07 +00:00
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
: base_t(x.base_t::get())
2016-03-02 05:27:27 +00:00
{}
2017-03-13 04:29:07 +00:00
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
{ this->base_t::get() = x.base_t::get(); return *this; }
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
{ this->base_t::get() = x; return *this; }
BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
2016-03-02 05:27:27 +00:00
{ return static_cast<const key_compare &>(*this); }
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key) const
{ return this->key_comp()(key); }
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value) const
{ return this->key_comp()(KeyOfValue()(value)); }
template<class U>
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(nonkey); }
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const key_type &key2) const
2017-03-13 04:29:07 +00:00
{ return this->key_comp()(key1, key2); }
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value1, const value_type &value2) const
2017-03-13 04:29:07 +00:00
{ return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); }
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const value_type &value2) const
2017-03-13 04:29:07 +00:00
{ return this->key_comp()(key1, KeyOfValue()(value2)); }
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value1, const key_type &key2) const
2017-03-13 04:29:07 +00:00
{ return this->key_comp()(KeyOfValue()(value1), key2); }
template<class U>
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const key_type &key1, const U &nonkey2
2017-03-13 04:29:07 +00:00
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(key1, nonkey2); }
2016-03-02 05:27:27 +00:00
template<class U>
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey1, const key_type &key2
2017-03-13 04:29:07 +00:00
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(nonkey1, key2); }
2016-03-02 05:27:27 +00:00
template<class U>
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const value_type &value1, const U &nonvalue2
2017-03-13 04:29:07 +00:00
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(KeyOfValue()(value1), nonvalue2); }
2016-03-02 05:27:27 +00:00
template<class U>
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonvalue1, const value_type &value2
2017-03-13 04:29:07 +00:00
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(nonvalue1, KeyOfValue()(value2)); }
};
2019-08-24 13:39:04 +00:00
template<class ValuePtr, class KeyCompare, class KeyOfValue, class Ret>
struct tree_value_compare<ValuePtr, KeyCompare, KeyOfValue, Ret, true>
2017-03-13 04:29:07 +00:00
: public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
{
2018-01-01 20:31:13 +00:00
typedef typename
boost::movelib::pointer_element<ValuePtr>::type value_type;
2017-03-13 04:29:07 +00:00
typedef KeyCompare key_compare;
typedef KeyOfValue key_of_value;
typedef typename KeyOfValue::type key_type;
typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
: base_t()
{}
2016-03-02 05:27:27 +00:00
2017-03-13 04:29:07 +00:00
BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
: base_t(kcomp)
{}
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
: base_t(x.base_t::get())
{}
2016-03-02 05:27:27 +00:00
2017-03-13 04:29:07 +00:00
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
{ this->base_t::get() = x.base_t::get(); return *this; }
BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
{ this->base_t::get() = x; return *this; }
BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
{ return static_cast<const key_compare &>(*this); }
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key) const
{ return this->key_comp()(key); }
template<class U>
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(nonkey); }
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const key_type &key2) const
2017-03-13 04:29:07 +00:00
{ return this->key_comp()(key1, key2); }
template<class U>
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const key_type &key1, const U &nonkey2
2017-03-13 04:29:07 +00:00
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(key1, nonkey2); }
template<class U>
2019-08-24 13:39:04 +00:00
BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const U &nonkey1, const key_type &key2
2017-03-13 04:29:07 +00:00
, typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
{ return this->key_comp()(nonkey1, key2); }
2016-03-02 05:27:27 +00:00
};
} //namespace intrusive{
} //namespace boost{
#endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP