xref: /freebsd/contrib/llvm-project/libcxx/include/__functional/ranges_operations.h (revision 725a9f47324d42037db93c27ceb40d4956872f3e)
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/operation_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(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))) {
35     return std::forward<_Tp>(__t) == std::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(!(std::forward<_Tp>(__t) == std::forward<_Up>(__u))))) {
46     return !(std::forward<_Tp>(__t) == std::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(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))) {
57     return std::forward<_Tp>(__t) < std::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(!(std::forward<_Up>(__u) < std::forward<_Tp>(__t))))) {
68     return !(std::forward<_Up>(__u) < std::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(std::forward<_Up>(__u) < std::forward<_Tp>(__t)))) {
79     return std::forward<_Up>(__u) < std::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(!(std::forward<_Tp>(__t) < std::forward<_Up>(__u))))) {
90     return !(std::forward<_Tp>(__t) < std::forward<_Up>(__u));
91   }
92 
93   using is_transparent = void;
94 };
95 
96 } // namespace ranges
97 
98 // For ranges we do not require that the types on each side of the equality
99 // operator are of the same type
100 template <class _Tp, class _Up>
101 struct __desugars_to<__equal_tag, ranges::equal_to, _Tp, _Up> : true_type {};
102 
103 #endif // _LIBCPP_STD_VER >= 20
104 
105 _LIBCPP_END_NAMESPACE_STD
106 
107 #endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
108