You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.8KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. // Copyright Casey Carter 2016
  6. //
  7. // Use, modification and distribution is subject to the
  8. // Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. //
  12. // Project home: https://github.com/ericniebler/range-v3
  13. //
  14. #ifndef RANGES_V3_FUNCTIONAL_COMPARISONS_HPP
  15. #define RANGES_V3_FUNCTIONAL_COMPARISONS_HPP
  16. #include <concepts/concepts.hpp>
  17. #include <range/v3/range_fwd.hpp>
  18. namespace ranges
  19. {
  20. /// \addtogroup group-functional
  21. /// @{
  22. struct equal_to
  23. {
  24. template<typename T, typename U>
  25. constexpr auto operator()(T && t, U && u) const -> CPP_ret(bool)( //
  26. requires equality_comparable_with<T, U>)
  27. {
  28. return (T &&) t == (U &&) u;
  29. }
  30. using is_transparent = void;
  31. };
  32. struct not_equal_to
  33. {
  34. template<typename T, typename U>
  35. constexpr auto operator()(T && t, U && u) const -> CPP_ret(bool)( //
  36. requires equality_comparable_with<T, U>)
  37. {
  38. return !equal_to{}((T &&) t, (U &&) u);
  39. }
  40. using is_transparent = void;
  41. };
  42. struct less
  43. {
  44. template<typename T, typename U>
  45. constexpr auto operator()(T && t, U && u) const -> CPP_ret(bool)( //
  46. requires totally_ordered_with<T, U>)
  47. {
  48. return (T &&) t < (U &&) u;
  49. }
  50. using is_transparent = void;
  51. };
  52. struct less_equal
  53. {
  54. template<typename T, typename U>
  55. constexpr auto operator()(T && t, U && u) const -> CPP_ret(bool)( //
  56. requires totally_ordered_with<T, U>)
  57. {
  58. return !less{}((U &&) u, (T &&) t);
  59. }
  60. using is_transparent = void;
  61. };
  62. struct greater_equal
  63. {
  64. template<typename T, typename U>
  65. constexpr auto operator()(T && t, U && u) const -> CPP_ret(bool)( //
  66. requires totally_ordered_with<T, U>)
  67. {
  68. return !less{}((T &&) t, (U &&) u);
  69. }
  70. using is_transparent = void;
  71. };
  72. struct greater
  73. {
  74. template<typename T, typename U>
  75. constexpr auto operator()(T && t, U && u) const -> CPP_ret(bool)( //
  76. requires totally_ordered_with<T, U>)
  77. {
  78. return less{}((U &&) u, (T &&) t);
  79. }
  80. using is_transparent = void;
  81. };
  82. using ordered_less RANGES_DEPRECATED(
  83. "Repace uses of ranges::ordered_less with ranges::less") = less;
  84. namespace cpp20
  85. {
  86. using ranges::equal_to;
  87. using ranges::greater;
  88. using ranges::greater_equal;
  89. using ranges::less;
  90. using ranges::less_equal;
  91. using ranges::not_equal_to;
  92. } // namespace cpp20
  93. /// @}
  94. } // namespace ranges
  95. #endif