From 60aea31db72b8941341f409f22e0367d342ad24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 15 Sep 2018 01:21:47 +0200 Subject: [PATCH] Make value_to_node_compare return type configurable --- .../container/detail/compare_functors.hpp | 66 +++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/include/boost/container/detail/compare_functors.hpp b/include/boost/container/detail/compare_functors.hpp index 28f9093..2c8dc6a 100644 --- a/include/boost/container/detail/compare_functors.hpp +++ b/include/boost/container/detail/compare_functors.hpp @@ -19,6 +19,8 @@ # pragma once #endif +#include + namespace boost { namespace container { @@ -37,7 +39,7 @@ class equal_to_value { return t_ == t; } }; -template +template struct value_to_node_compare : Pred { @@ -52,22 +54,76 @@ struct value_to_node_compare : Pred(pred) {} - bool operator()(const Node &a, const Node &b) const + Ret operator()(const Node &a, const Node &b) const { return static_cast(*this)(a.get_data(), b.get_data()); } - bool operator()(const Node &a) const + Ret operator()(const Node &a) const { return static_cast(*this)(a.get_data()); } - bool operator()(const Node &a, const Node &b) + Ret operator()(const Node &a, const Node &b) { return static_cast(*this)(a.get_data(), b.get_data()); } - bool operator()(const Node &a) + Ret operator()(const Node &a) { return static_cast(*this)(a.get_data()); } predicate_type & predicate() { return static_cast(*this); } const predicate_type & predicate() const { return static_cast(*this); } }; +template +struct key_node_pred + : public boost::intrusive::detail::ebo_functor_holder +{ + BOOST_CONTAINER_FORCEINLINE explicit key_node_pred(const KeyPred &comp) + : base_t(comp) + {} + + typedef boost::intrusive::detail::ebo_functor_holder base_t; + typedef KeyPred key_predicate; + typedef KeyOfValue key_of_value; + typedef typename KeyOfValue::type key_type; + + + BOOST_CONTAINER_FORCEINLINE static const key_type &key_from(const Node &n) + { + return key_of_value()(n.get_data()); + } + + template + BOOST_CONTAINER_FORCEINLINE static const T & + key_from(const T &t) + { return t; } + + BOOST_CONTAINER_FORCEINLINE const key_predicate &key_pred() const + { return static_cast(*this); } + + BOOST_CONTAINER_FORCEINLINE key_predicate &key_pred() + { return static_cast(*this); } + + BOOST_CONTAINER_FORCEINLINE Ret operator()(const key_type &key) const + { return this->key_pred()(key); } + + template + BOOST_CONTAINER_FORCEINLINE Ret operator()(const U &nonkey) const + { return this->key_pred()(this->key_from(nonkey)); } + + BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const + { return this->key_pred()(key1, key2); } + + template + BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const U &nonkey2) const + { return this->key_pred()(key1, this->key_from(nonkey2)); } + + template + BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2) const + { return this->key_pred()(this->key_from(nonkey1), key2); } + + template + BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const V &nonkey2) const + { return this->key_pred()(this->key_from(nonkey1), this->key_from(nonkey2)); } +}; + + } //namespace container { } //namespace boost {