ranges_operations.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <__config>
  12. #include <__utility/forward.h>
  13. #include <concepts>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. #if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
  19. namespace ranges {
  20. struct equal_to {
  21. template <class _Tp, class _Up>
  22. requires equality_comparable_with<_Tp, _Up>
  23. [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  24. noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
  25. return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
  26. }
  27. using is_transparent = void;
  28. };
  29. struct not_equal_to {
  30. template <class _Tp, class _Up>
  31. requires equality_comparable_with<_Tp, _Up>
  32. [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  33. noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
  34. return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
  35. }
  36. using is_transparent = void;
  37. };
  38. struct less {
  39. template <class _Tp, class _Up>
  40. requires totally_ordered_with<_Tp, _Up>
  41. [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  42. noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
  43. return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
  44. }
  45. using is_transparent = void;
  46. };
  47. struct less_equal {
  48. template <class _Tp, class _Up>
  49. requires totally_ordered_with<_Tp, _Up>
  50. [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  51. noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
  52. return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
  53. }
  54. using is_transparent = void;
  55. };
  56. struct greater {
  57. template <class _Tp, class _Up>
  58. requires totally_ordered_with<_Tp, _Up>
  59. [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  60. noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
  61. return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
  62. }
  63. using is_transparent = void;
  64. };
  65. struct greater_equal {
  66. template <class _Tp, class _Up>
  67. requires totally_ordered_with<_Tp, _Up>
  68. [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
  69. noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
  70. return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
  71. }
  72. using is_transparent = void;
  73. };
  74. } // namespace ranges
  75. #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
  76. _LIBCPP_END_NAMESPACE_STD
  77. #endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H