xref: /llvm-project/libcxx/include/__functional/ranges_operations.h (revision 0fb76bae6b2abfe5e0a34557f365a586be989364)
1050b064fSChristopher Di Bella // -*- C++ -*-
2050b064fSChristopher Di Bella //===----------------------------------------------------------------------===//
3050b064fSChristopher Di Bella //
4050b064fSChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5050b064fSChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information.
6050b064fSChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7050b064fSChristopher Di Bella //
8050b064fSChristopher Di Bella //===----------------------------------------------------------------------===//
9050b064fSChristopher Di Bella 
10050b064fSChristopher Di Bella #ifndef _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
11050b064fSChristopher Di Bella #define _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
12050b064fSChristopher Di Bella 
1389b356f0SNikolas Klauser #include <__concepts/equality_comparable.h>
1489b356f0SNikolas Klauser #include <__concepts/totally_ordered.h>
15050b064fSChristopher Di Bella #include <__config>
16f5960c16SNikolas Klauser #include <__type_traits/desugars_to.h>
17ea2206d7SArthur O'Dwyer #include <__utility/forward.h>
18050b064fSChristopher Di Bella 
19050b064fSChristopher Di Bella #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20050b064fSChristopher Di Bella #  pragma GCC system_header
21050b064fSChristopher Di Bella #endif
22050b064fSChristopher Di Bella 
23050b064fSChristopher Di Bella _LIBCPP_BEGIN_NAMESPACE_STD
24050b064fSChristopher Di Bella 
254f15267dSNikolas Klauser #if _LIBCPP_STD_VER >= 20
2653406fb6SArthur O'Dwyer 
27050b064fSChristopher Di Bella namespace ranges {
28050b064fSChristopher Di Bella 
29050b064fSChristopher Di Bella struct equal_to {
30050b064fSChristopher Di Bella   template <class _Tp, class _Up>
31050b064fSChristopher Di Bella     requires equality_comparable_with<_Tp, _Up>
3283ce1397SNikolas Klauser   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
3377a00c0dSLouis Dionne       noexcept(noexcept(bool(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))) {
3477a00c0dSLouis Dionne     return std::forward<_Tp>(__t) == std::forward<_Up>(__u);
35050b064fSChristopher Di Bella   }
36050b064fSChristopher Di Bella 
37050b064fSChristopher Di Bella   using is_transparent = void;
38050b064fSChristopher Di Bella };
39050b064fSChristopher Di Bella 
40050b064fSChristopher Di Bella struct not_equal_to {
41050b064fSChristopher Di Bella   template <class _Tp, class _Up>
42050b064fSChristopher Di Bella     requires equality_comparable_with<_Tp, _Up>
4383ce1397SNikolas Klauser   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
4477a00c0dSLouis Dionne       noexcept(noexcept(bool(!(std::forward<_Tp>(__t) == std::forward<_Up>(__u))))) {
4577a00c0dSLouis Dionne     return !(std::forward<_Tp>(__t) == std::forward<_Up>(__u));
46050b064fSChristopher Di Bella   }
47050b064fSChristopher Di Bella 
48050b064fSChristopher Di Bella   using is_transparent = void;
49050b064fSChristopher Di Bella };
50050b064fSChristopher Di Bella 
51050b064fSChristopher Di Bella struct less {
52050b064fSChristopher Di Bella   template <class _Tp, class _Up>
53050b064fSChristopher Di Bella     requires totally_ordered_with<_Tp, _Up>
5483ce1397SNikolas Klauser   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
5577a00c0dSLouis Dionne       noexcept(noexcept(bool(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))) {
5677a00c0dSLouis Dionne     return std::forward<_Tp>(__t) < std::forward<_Up>(__u);
57050b064fSChristopher Di Bella   }
58050b064fSChristopher Di Bella 
59050b064fSChristopher Di Bella   using is_transparent = void;
60050b064fSChristopher Di Bella };
61050b064fSChristopher Di Bella 
62050b064fSChristopher Di Bella struct less_equal {
63050b064fSChristopher Di Bella   template <class _Tp, class _Up>
64050b064fSChristopher Di Bella     requires totally_ordered_with<_Tp, _Up>
6583ce1397SNikolas Klauser   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
6677a00c0dSLouis Dionne       noexcept(noexcept(bool(!(std::forward<_Up>(__u) < std::forward<_Tp>(__t))))) {
6777a00c0dSLouis Dionne     return !(std::forward<_Up>(__u) < std::forward<_Tp>(__t));
68050b064fSChristopher Di Bella   }
69050b064fSChristopher Di Bella 
70050b064fSChristopher Di Bella   using is_transparent = void;
71050b064fSChristopher Di Bella };
72050b064fSChristopher Di Bella 
73050b064fSChristopher Di Bella struct greater {
74050b064fSChristopher Di Bella   template <class _Tp, class _Up>
75050b064fSChristopher Di Bella     requires totally_ordered_with<_Tp, _Up>
7683ce1397SNikolas Klauser   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
7777a00c0dSLouis Dionne       noexcept(noexcept(bool(std::forward<_Up>(__u) < std::forward<_Tp>(__t)))) {
7877a00c0dSLouis Dionne     return std::forward<_Up>(__u) < std::forward<_Tp>(__t);
79050b064fSChristopher Di Bella   }
80050b064fSChristopher Di Bella 
81050b064fSChristopher Di Bella   using is_transparent = void;
82050b064fSChristopher Di Bella };
83050b064fSChristopher Di Bella 
84050b064fSChristopher Di Bella struct greater_equal {
85050b064fSChristopher Di Bella   template <class _Tp, class _Up>
86050b064fSChristopher Di Bella     requires totally_ordered_with<_Tp, _Up>
8783ce1397SNikolas Klauser   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
8877a00c0dSLouis Dionne       noexcept(noexcept(bool(!(std::forward<_Tp>(__t) < std::forward<_Up>(__u))))) {
8977a00c0dSLouis Dionne     return !(std::forward<_Tp>(__t) < std::forward<_Up>(__u));
90050b064fSChristopher Di Bella   }
91050b064fSChristopher Di Bella 
92050b064fSChristopher Di Bella   using is_transparent = void;
93050b064fSChristopher Di Bella };
94050b064fSChristopher Di Bella 
95050b064fSChristopher Di Bella } // namespace ranges
96d4853e63SArthur O'Dwyer 
97aea7929bSAnton Rydahl // For ranges we do not require that the types on each side of the equality
98aea7929bSAnton Rydahl // operator are of the same type
99aea7929bSAnton Rydahl template <class _Tp, class _Up>
100f5960c16SNikolas Klauser inline const bool __desugars_to_v<__equal_tag, ranges::equal_to, _Tp, _Up> = true;
101b4ecfd3cSNikolas Klauser 
102935e6991SNikolas Klauser template <class _Tp, class _Up>
103d07fdf97SNikolas Klauser inline const bool __desugars_to_v<__totally_ordered_less_tag, ranges::less, _Tp, _Up> = true;
104935e6991SNikolas Klauser 
105*0fb76baeSNikolas Klauser template <class _Tp, class _Up>
106*0fb76baeSNikolas Klauser inline const bool __desugars_to_v<__less_tag, ranges::less, _Tp, _Up> = true;
107*0fb76baeSNikolas Klauser 
108*0fb76baeSNikolas Klauser template <class _Tp, class _Up>
109*0fb76baeSNikolas Klauser inline const bool __desugars_to_v<__greater_tag, ranges::greater, _Tp, _Up> = true;
110*0fb76baeSNikolas Klauser 
1114f15267dSNikolas Klauser #endif // _LIBCPP_STD_VER >= 20
112050b064fSChristopher Di Bella 
113050b064fSChristopher Di Bella _LIBCPP_END_NAMESPACE_STD
114050b064fSChristopher Di Bella 
115050b064fSChristopher Di Bella #endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H
116