xref: /freebsd/contrib/llvm-project/libcxx/include/__functional/ranges_operations.h (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
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 
10 #ifndef _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
11 #define _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
12 
13 #include <__concepts/equality_comparable.h>
14 #include <__concepts/totally_ordered.h>
15 #include <__config>
16 #include <__type_traits/integral_constant.h>
17 #include <__type_traits/predicate_traits.h>
18 #include <__utility/forward.h>
19 
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #  pragma GCC system_header
22 #endif
23 
24 _LIBCPP_BEGIN_NAMESPACE_STD
25 
26 #if _LIBCPP_STD_VER >= 20
27 
28 namespace ranges {
29 
30 struct equal_to {
31   template <class _Tp, class _Up>
32   requires equality_comparable_with<_Tp, _Up>
33   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
34       noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
35     return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
36   }
37 
38   using is_transparent = void;
39 };
40 
41 struct not_equal_to {
42   template <class _Tp, class _Up>
43   requires equality_comparable_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 
49   using is_transparent = void;
50 };
51 
52 struct less {
53   template <class _Tp, class _Up>
54   requires totally_ordered_with<_Tp, _Up>
55   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
56       noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
57     return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
58   }
59 
60   using is_transparent = void;
61 };
62 
63 struct less_equal {
64   template <class _Tp, class _Up>
65   requires totally_ordered_with<_Tp, _Up>
66   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
67       noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
68     return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
69   }
70 
71   using is_transparent = void;
72 };
73 
74 struct greater {
75   template <class _Tp, class _Up>
76   requires totally_ordered_with<_Tp, _Up>
77   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
78       noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
79     return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
80   }
81 
82   using is_transparent = void;
83 };
84 
85 struct greater_equal {
86   template <class _Tp, class _Up>
87   requires totally_ordered_with<_Tp, _Up>
88   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp &&__t, _Up &&__u) const
89       noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
90     return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
91   }
92 
93   using is_transparent = void;
94 };
95 
96 } // namespace ranges
97 
98 template <class _Lhs, class _Rhs>
99 struct __is_trivial_equality_predicate<ranges::equal_to, _Lhs, _Rhs> : true_type {};
100 
101 #endif // _LIBCPP_STD_VER >= 20
102 
103 _LIBCPP_END_NAMESPACE_STD
104 
105 #endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
106