File indexing completed on 2025-01-18 09:30:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP
0012 #define BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024
0025 namespace boost {
0026 namespace container {
0027
0028 template<class ValueType>
0029 class equal_to_value
0030 {
0031 typedef ValueType value_type;
0032 const value_type &t_;
0033
0034 public:
0035 BOOST_CONTAINER_FORCEINLINE explicit equal_to_value(const value_type &t)
0036 : t_(t)
0037 {}
0038
0039 BOOST_CONTAINER_FORCEINLINE bool operator()(const value_type &t)const
0040 { return t_ == t; }
0041 };
0042
0043 template<class Node, class Pred, class Ret = bool>
0044 struct value_to_node_compare
0045 : Pred
0046 {
0047 typedef Pred predicate_type;
0048 typedef Node node_type;
0049
0050 BOOST_CONTAINER_FORCEINLINE value_to_node_compare()
0051 : Pred()
0052 {}
0053
0054 BOOST_CONTAINER_FORCEINLINE explicit value_to_node_compare(Pred pred)
0055 : Pred(pred)
0056 {}
0057
0058 BOOST_CONTAINER_FORCEINLINE Ret operator()(const Node &a, const Node &b) const
0059 { return static_cast<const Pred&>(*this)(a.get_data(), b.get_data()); }
0060
0061 BOOST_CONTAINER_FORCEINLINE Ret operator()(const Node &a) const
0062 { return static_cast<const Pred&>(*this)(a.get_data()); }
0063
0064 BOOST_CONTAINER_FORCEINLINE Ret operator()(const Node &a, const Node &b)
0065 { return static_cast<Pred&>(*this)(a.get_data(), b.get_data()); }
0066
0067 BOOST_CONTAINER_FORCEINLINE Ret operator()(const Node &a)
0068 { return static_cast<Pred&>(*this)(a.get_data()); }
0069
0070 BOOST_CONTAINER_FORCEINLINE predicate_type & predicate() { return static_cast<predicate_type&>(*this); }
0071 BOOST_CONTAINER_FORCEINLINE const predicate_type & predicate() const { return static_cast<predicate_type&>(*this); }
0072 };
0073
0074 template<class KeyPred, class KeyOfValue, class Node, class Ret = bool>
0075 struct key_node_pred
0076 : public boost::intrusive::detail::ebo_functor_holder<KeyPred>
0077 {
0078 BOOST_CONTAINER_FORCEINLINE explicit key_node_pred(const KeyPred &comp)
0079 : base_t(comp)
0080 {}
0081
0082 BOOST_CONTAINER_FORCEINLINE explicit key_node_pred()
0083 {}
0084
0085 typedef boost::intrusive::detail::ebo_functor_holder<KeyPred> base_t;
0086 typedef KeyPred key_predicate;
0087 typedef KeyOfValue key_of_value;
0088 typedef typename KeyOfValue::type key_type;
0089
0090
0091 BOOST_CONTAINER_FORCEINLINE static const key_type &key_from(const Node &n)
0092 {
0093 return key_of_value()(n.get_data());
0094 }
0095
0096 template <class T>
0097 BOOST_CONTAINER_FORCEINLINE static const T &
0098 key_from(const T &t)
0099 { return t; }
0100
0101 BOOST_CONTAINER_FORCEINLINE const key_predicate &key_pred() const
0102 { return static_cast<const key_predicate &>(*this); }
0103
0104 BOOST_CONTAINER_FORCEINLINE key_predicate &key_pred()
0105 { return static_cast<key_predicate &>(*this); }
0106
0107 BOOST_CONTAINER_FORCEINLINE Ret operator()(const key_type &key) const
0108 { return this->key_pred()(key); }
0109
0110 template<class U>
0111 BOOST_CONTAINER_FORCEINLINE Ret operator()(const U &nonkey) const
0112 { return this->key_pred()(this->key_from(nonkey)); }
0113
0114 BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
0115 { return this->key_pred()(key1, key2); }
0116
0117 template<class U>
0118 BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const U &nonkey2) const
0119 { return this->key_pred()(key1, this->key_from(nonkey2)); }
0120
0121 template<class U>
0122 BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2) const
0123 { return this->key_pred()(this->key_from(nonkey1), key2); }
0124
0125 template<class U, class V>
0126 BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const V &nonkey2) const
0127 { return this->key_pred()(this->key_from(nonkey1), this->key_from(nonkey2)); }
0128 };
0129
0130
0131 }
0132 }
0133
0134 #endif