predicate.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2016.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/move for documentation.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. #ifndef BOOST_MOVE_ALGO_PREDICATE_HPP
  12. #define BOOST_MOVE_ALGO_PREDICATE_HPP
  13. #include <boost/move/algo/move.hpp>
  14. #include <boost/move/adl_move_swap.hpp>
  15. #include <boost/move/algo/detail/basic_op.hpp>
  16. #include <boost/move/detail/iterator_traits.hpp>
  17. #include <boost/move/detail/destruct_n.hpp>
  18. #include <boost/assert.hpp>
  19. namespace boost {
  20. namespace movelib {
  21. template<class Comp>
  22. struct antistable
  23. {
  24. explicit antistable(Comp &comp)
  25. : m_comp(comp)
  26. {}
  27. antistable(const antistable & other)
  28. : m_comp(other.m_comp)
  29. {}
  30. template<class U, class V>
  31. bool operator()(const U &u, const V & v)
  32. { return !m_comp(v, u); }
  33. const Comp &get() const
  34. { return m_comp; }
  35. private:
  36. antistable & operator=(const antistable &);
  37. Comp &m_comp;
  38. };
  39. template<class Comp>
  40. Comp unantistable(Comp comp)
  41. { return comp; }
  42. template<class Comp>
  43. Comp unantistable(antistable<Comp> comp)
  44. { return comp.get(); }
  45. template <class Comp>
  46. class negate
  47. {
  48. public:
  49. negate()
  50. {}
  51. explicit negate(Comp comp)
  52. : m_comp(comp)
  53. {}
  54. template <class T1, class T2>
  55. bool operator()(const T1& l, const T2& r)
  56. {
  57. return !m_comp(l, r);
  58. }
  59. private:
  60. Comp m_comp;
  61. };
  62. template <class Comp>
  63. class inverse
  64. {
  65. public:
  66. inverse()
  67. {}
  68. explicit inverse(Comp comp)
  69. : m_comp(comp)
  70. {}
  71. template <class T1, class T2>
  72. bool operator()(const T1& l, const T2& r)
  73. {
  74. return m_comp(r, l);
  75. }
  76. private:
  77. Comp m_comp;
  78. };
  79. } //namespace movelib {
  80. } //namespace boost {
  81. #endif //#define BOOST_MOVE_ALGO_PREDICATE_HPP