compare_functors.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP
  11. #define BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. namespace boost {
  19. namespace container {
  20. template<class Allocator>
  21. class equal_to_value
  22. {
  23. typedef typename Allocator::value_type value_type;
  24. const value_type &t_;
  25. public:
  26. explicit equal_to_value(const value_type &t)
  27. : t_(t)
  28. {}
  29. bool operator()(const value_type &t)const
  30. { return t_ == t; }
  31. };
  32. template<class Node, class Pred>
  33. struct value_to_node_compare
  34. : Pred
  35. {
  36. typedef Pred predicate_type;
  37. typedef Node node_type;
  38. value_to_node_compare()
  39. : Pred()
  40. {}
  41. explicit value_to_node_compare(Pred pred)
  42. : Pred(pred)
  43. {}
  44. bool operator()(const Node &a, const Node &b) const
  45. { return static_cast<const Pred&>(*this)(a.get_data(), b.get_data()); }
  46. bool operator()(const Node &a) const
  47. { return static_cast<const Pred&>(*this)(a.get_data()); }
  48. bool operator()(const Node &a, const Node &b)
  49. { return static_cast<Pred&>(*this)(a.get_data(), b.get_data()); }
  50. bool operator()(const Node &a)
  51. { return static_cast<Pred&>(*this)(a.get_data()); }
  52. predicate_type & predicate() { return static_cast<predicate_type&>(*this); }
  53. const predicate_type & predicate() const { return static_cast<predicate_type&>(*this); }
  54. };
  55. } //namespace container {
  56. } //namespace boost {
  57. #endif //BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP