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 #include <boost/container/detail/workaround.hpp> 24 25 namespace boost { 26 namespace container { 27 28 template<class ValueType> 29 class equal_to_value 30 { 31 typedef ValueType value_type; 32 const value_type &t_; 33 34 public: equal_to_value(const value_type & t)35 explicit equal_to_value(const value_type &t) 36 : t_(t) 37 {} 38 operator ()(const value_type & t) const39 bool operator()(const value_type &t)const 40 { return t_ == t; } 41 }; 42 43 template<class Node, class Pred, class Ret = bool> 44 struct value_to_node_compare 45 : Pred 46 { 47 typedef Pred predicate_type; 48 typedef Node node_type; 49 value_to_node_compareboost::container::value_to_node_compare50 value_to_node_compare() 51 : Pred() 52 {} 53 value_to_node_compareboost::container::value_to_node_compare54 explicit value_to_node_compare(Pred pred) 55 : Pred(pred) 56 {} 57 operator ()boost::container::value_to_node_compare58 Ret operator()(const Node &a, const Node &b) const 59 { return static_cast<const Pred&>(*this)(a.get_data(), b.get_data()); } 60 operator ()boost::container::value_to_node_compare61 Ret operator()(const Node &a) const 62 { return static_cast<const Pred&>(*this)(a.get_data()); } 63 operator ()boost::container::value_to_node_compare64 Ret operator()(const Node &a, const Node &b) 65 { return static_cast<Pred&>(*this)(a.get_data(), b.get_data()); } 66 operator ()boost::container::value_to_node_compare67 Ret operator()(const Node &a) 68 { return static_cast<Pred&>(*this)(a.get_data()); } 69 predicateboost::container::value_to_node_compare70 predicate_type & predicate() { return static_cast<predicate_type&>(*this); } predicateboost::container::value_to_node_compare71 const predicate_type & predicate() const { return static_cast<predicate_type&>(*this); } 72 }; 73 74 template<class KeyPred, class KeyOfValue, class Node, class Ret = bool> 75 struct key_node_pred 76 : public boost::intrusive::detail::ebo_functor_holder<KeyPred> 77 { key_node_predboost::container::key_node_pred78 BOOST_CONTAINER_FORCEINLINE explicit key_node_pred(const KeyPred &comp) 79 : base_t(comp) 80 {} 81 82 typedef boost::intrusive::detail::ebo_functor_holder<KeyPred> base_t; 83 typedef KeyPred key_predicate; 84 typedef KeyOfValue key_of_value; 85 typedef typename KeyOfValue::type key_type; 86 87 key_fromboost::container::key_node_pred88 BOOST_CONTAINER_FORCEINLINE static const key_type &key_from(const Node &n) 89 { 90 return key_of_value()(n.get_data()); 91 } 92 93 template <class T> 94 BOOST_CONTAINER_FORCEINLINE static const T & key_fromboost::container::key_node_pred95 key_from(const T &t) 96 { return t; } 97 key_predboost::container::key_node_pred98 BOOST_CONTAINER_FORCEINLINE const key_predicate &key_pred() const 99 { return static_cast<const key_predicate &>(*this); } 100 key_predboost::container::key_node_pred101 BOOST_CONTAINER_FORCEINLINE key_predicate &key_pred() 102 { return static_cast<key_predicate &>(*this); } 103 operator ()boost::container::key_node_pred104 BOOST_CONTAINER_FORCEINLINE Ret operator()(const key_type &key) const 105 { return this->key_pred()(key); } 106 107 template<class U> operator ()boost::container::key_node_pred108 BOOST_CONTAINER_FORCEINLINE Ret operator()(const U &nonkey) const 109 { return this->key_pred()(this->key_from(nonkey)); } 110 operator ()boost::container::key_node_pred111 BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const 112 { return this->key_pred()(key1, key2); } 113 114 template<class U> operator ()boost::container::key_node_pred115 BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const U &nonkey2) const 116 { return this->key_pred()(key1, this->key_from(nonkey2)); } 117 118 template<class U> operator ()boost::container::key_node_pred119 BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2) const 120 { return this->key_pred()(this->key_from(nonkey1), key2); } 121 122 template<class U, class V> operator ()boost::container::key_node_pred123 BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const V &nonkey2) const 124 { return this->key_pred()(this->key_from(nonkey1), this->key_from(nonkey2)); } 125 }; 126 127 128 } //namespace container { 129 } //namespace boost { 130 131 #endif //BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP 132