predicate.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. template<class U, class V>
  28. bool operator()(const U &u, const V & v)
  29. { return !m_comp(v, u); }
  30. private:
  31. antistable & operator=(const antistable &);
  32. Comp &m_comp;
  33. };
  34. template <class Comp>
  35. class negate
  36. {
  37. public:
  38. negate()
  39. {}
  40. explicit negate(Comp comp)
  41. : m_comp(comp)
  42. {}
  43. template <class T1, class T2>
  44. bool operator()(const T1& l, const T2& r)
  45. {
  46. return !m_comp(l, r);
  47. }
  48. private:
  49. Comp m_comp;
  50. };
  51. template <class Comp>
  52. class inverse
  53. {
  54. public:
  55. inverse()
  56. {}
  57. explicit inverse(Comp comp)
  58. : m_comp(comp)
  59. {}
  60. template <class T1, class T2>
  61. bool operator()(const T1& l, const T2& r)
  62. {
  63. return m_comp(r, l);
  64. }
  65. private:
  66. Comp m_comp;
  67. };
  68. } //namespace movelib {
  69. } //namespace boost {
  70. #endif //#define BOOST_MOVE_ALGO_PREDICATE_HPP