ranges_operations.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
  10. #define _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
  11. #include <__concepts/equality_comparable.h>
  12. #include <__concepts/totally_ordered.h>
  13. #include <__config>
  14. #include <__type_traits/integral_constant.h>
  15. #include <__type_traits/predicate_traits.h>
  16. #include <__utility/forward.h>
  17. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  18. # pragma GCC system_header
  19. #endif
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. #if _LIBCPP_STD_VER >= 20
  22. namespace ranges {
  23. struct equal_to {
  24. template <class _Tp, class _Up>
  25. requires equality_comparable_with<_Tp, _Up>
  26. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  27. noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
  28. return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
  29. }
  30. using is_transparent = void;
  31. };
  32. struct not_equal_to {
  33. template <class _Tp, class _Up>
  34. requires equality_comparable_with<_Tp, _Up>
  35. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  36. noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
  37. return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
  38. }
  39. using is_transparent = void;
  40. };
  41. struct less {
  42. template <class _Tp, class _Up>
  43. requires totally_ordered_with<_Tp, _Up>
  44. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  45. noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
  46. return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
  47. }
  48. using is_transparent = void;
  49. };
  50. struct less_equal {
  51. template <class _Tp, class _Up>
  52. requires totally_ordered_with<_Tp, _Up>
  53. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  54. noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
  55. return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
  56. }
  57. using is_transparent = void;
  58. };
  59. struct greater {
  60. template <class _Tp, class _Up>
  61. requires totally_ordered_with<_Tp, _Up>
  62. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  63. noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
  64. return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
  65. }
  66. using is_transparent = void;
  67. };
  68. struct greater_equal {
  69. template <class _Tp, class _Up>
  70. requires totally_ordered_with<_Tp, _Up>
  71. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  72. noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
  73. return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
  74. }
  75. using is_transparent = void;
  76. };
  77. } // namespace ranges
  78. template <class _Lhs, class _Rhs>
  79. struct __is_trivial_equality_predicate<ranges::equal_to, _Lhs, _Rhs> : true_type {};
  80. #endif // _LIBCPP_STD_VER >= 20
  81. _LIBCPP_END_NAMESPACE_STD
  82. #endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H