1 /////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 // See http://www.boost.org/libs/container for documentation. 8 // 9 /////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP 12 #define BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP 13 14 #ifndef BOOST_CONFIG_HPP 15 # include <boost/config.hpp> 16 #endif 17 18 #if defined(BOOST_HAS_PRAGMA_ONCE) 19 # pragma once 20 #endif 21 22 #include <boost/intrusive/detail/ebo_functor_holder.hpp> 23 24 namespace boost { 25 namespace container { 26 27 template<class ValueType> 28 class equal_to_value 29 { 30 typedef ValueType value_type; 31 const value_type &t_; 32 33 public: equal_to_value(const value_type & t)34 explicit equal_to_value(const value_type &t) 35 : t_(t) 36 {} 37 operator ()(const value_type & t) const38 bool operator()(const value_type &t)const 39 { return t_ == t; } 40 }; 41 42 template<class Node, class Pred, class Ret = bool> 43 struct value_to_node_compare 44 : Pred 45 { 46 typedef Pred predicate_type; 47 typedef Node node_type; 48 value_to_node_compareboost::container::value_to_node_compare49 value_to_node_compare() 50 : Pred() 51 {} 52 value_to_node_compareboost::container::value_to_node_compare53 explicit value_to_node_compare(Pred pred) 54 : Pred(pred) 55 {} 56 operator ()boost::container::value_to_node_compare57 Ret operator()(const Node &a, const Node &b) const 58 { return static_cast<const Pred&>(*this)(a.get_data(), b.get_data()); } 59 operator ()boost::container::value_to_node_compare60 Ret operator()(const Node &a) const 61 { return static_cast<const Pred&>(*this)(a.get_data()); } 62 operator ()boost::container::value_to_node_compare63 Ret operator()(const Node &a, const Node &b) 64 { return static_cast<Pred&>(*this)(a.get_data(), b.get_data()); } 65 operator ()boost::container::value_to_node_compare66 Ret operator()(const Node &a) 67 { return static_cast<Pred&>(*this)(a.get_data()); } 68 predicateboost::container::value_to_node_compare69 predicate_type & predicate() { return static_cast<predicate_type&>(*this); } predicateboost::container::value_to_node_compare70 const predicate_type & predicate() const { return static_cast<predicate_type&>(*this); } 71 }; 72 73 template<class KeyPred, class KeyOfValue, class Node, class Ret = bool> 74 struct key_node_pred 75 : public boost::intrusive::detail::ebo_functor_holder<KeyPred> 76 { key_node_predboost::container::key_node_pred77 BOOST_CONTAINER_FORCEINLINE explicit key_node_pred(const KeyPred &comp) 78 : base_t(comp) 79 {} 80 81 typedef boost::intrusive::detail::ebo_functor_holder<KeyPred> base_t; 82 typedef KeyPred key_predicate; 83 typedef KeyOfValue key_of_value; 84 typedef typename KeyOfValue::type key_type; 85 86 key_fromboost::container::key_node_pred87 BOOST_CONTAINER_FORCEINLINE static const key_type &key_from(const Node &n) 88 { 89 return key_of_value()(n.get_data()); 90 } 91 92 template <class T> 93 BOOST_CONTAINER_FORCEINLINE static const T & key_fromboost::container::key_node_pred94 key_from(const T &t) 95 { return t; } 96 key_predboost::container::key_node_pred97 BOOST_CONTAINER_FORCEINLINE const key_predicate &key_pred() const 98 { return static_cast<const key_predicate &>(*this); } 99 key_predboost::container::key_node_pred100 BOOST_CONTAINER_FORCEINLINE key_predicate &key_pred() 101 { return static_cast<key_predicate &>(*this); } 102 operator ()boost::container::key_node_pred103 BOOST_CONTAINER_FORCEINLINE Ret operator()(const key_type &key) const 104 { return this->key_pred()(key); } 105 106 template<class U> operator ()boost::container::key_node_pred107 BOOST_CONTAINER_FORCEINLINE Ret operator()(const U &nonkey) const 108 { return this->key_pred()(this->key_from(nonkey)); } 109 operator ()boost::container::key_node_pred110 BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const 111 { return this->key_pred()(key1, key2); } 112 113 template<class U> operator ()boost::container::key_node_pred114 BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const U &nonkey2) const 115 { return this->key_pred()(key1, this->key_from(nonkey2)); } 116 117 template<class U> operator ()boost::container::key_node_pred118 BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2) const 119 { return this->key_pred()(this->key_from(nonkey1), key2); } 120 121 template<class U, class V> operator ()boost::container::key_node_pred122 BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const V &nonkey2) const 123 { return this->key_pred()(this->key_from(nonkey1), this->key_from(nonkey2)); } 124 }; 125 126 127 } //namespace container { 128 } //namespace boost { 129 130 #endif //BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP 131