master
  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/desugars_to.h>
 17#include <__utility/forward.h>
 18
 19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 20#  pragma GCC system_header
 21#endif
 22
 23_LIBCPP_BEGIN_NAMESPACE_STD
 24
 25#if _LIBCPP_STD_VER >= 20
 26
 27namespace ranges {
 28
 29struct equal_to {
 30  template <class _Tp, class _Up>
 31    requires equality_comparable_with<_Tp, _Up>
 32  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
 33      noexcept(noexcept(bool(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))) {
 34    return std::forward<_Tp>(__t) == std::forward<_Up>(__u);
 35  }
 36
 37  using is_transparent = void;
 38};
 39
 40struct not_equal_to {
 41  template <class _Tp, class _Up>
 42    requires equality_comparable_with<_Tp, _Up>
 43  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
 44      noexcept(noexcept(bool(!(std::forward<_Tp>(__t) == std::forward<_Up>(__u))))) {
 45    return !(std::forward<_Tp>(__t) == std::forward<_Up>(__u));
 46  }
 47
 48  using is_transparent = void;
 49};
 50
 51struct less {
 52  template <class _Tp, class _Up>
 53    requires totally_ordered_with<_Tp, _Up>
 54  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
 55      noexcept(noexcept(bool(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))) {
 56    return std::forward<_Tp>(__t) < std::forward<_Up>(__u);
 57  }
 58
 59  using is_transparent = void;
 60};
 61
 62struct less_equal {
 63  template <class _Tp, class _Up>
 64    requires totally_ordered_with<_Tp, _Up>
 65  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
 66      noexcept(noexcept(bool(!(std::forward<_Up>(__u) < std::forward<_Tp>(__t))))) {
 67    return !(std::forward<_Up>(__u) < std::forward<_Tp>(__t));
 68  }
 69
 70  using is_transparent = void;
 71};
 72
 73struct greater {
 74  template <class _Tp, class _Up>
 75    requires totally_ordered_with<_Tp, _Up>
 76  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
 77      noexcept(noexcept(bool(std::forward<_Up>(__u) < std::forward<_Tp>(__t)))) {
 78    return std::forward<_Up>(__u) < std::forward<_Tp>(__t);
 79  }
 80
 81  using is_transparent = void;
 82};
 83
 84struct greater_equal {
 85  template <class _Tp, class _Up>
 86    requires totally_ordered_with<_Tp, _Up>
 87  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t, _Up&& __u) const
 88      noexcept(noexcept(bool(!(std::forward<_Tp>(__t) < std::forward<_Up>(__u))))) {
 89    return !(std::forward<_Tp>(__t) < std::forward<_Up>(__u));
 90  }
 91
 92  using is_transparent = void;
 93};
 94
 95} // namespace ranges
 96
 97// For ranges we do not require that the types on each side of the equality
 98// operator are of the same type
 99template <class _Tp, class _Up>
100inline const bool __desugars_to_v<__equal_tag, ranges::equal_to, _Tp, _Up> = true;
101
102template <class _Tp, class _Up>
103inline const bool __desugars_to_v<__totally_ordered_less_tag, ranges::less, _Tp, _Up> = true;
104
105template <class _Tp, class _Up>
106inline const bool __desugars_to_v<__less_tag, ranges::less, _Tp, _Up> = true;
107
108template <class _Tp, class _Up>
109inline const bool __desugars_to_v<__greater_tag, ranges::greater, _Tp, _Up> = true;
110
111#endif // _LIBCPP_STD_VER >= 20
112
113_LIBCPP_END_NAMESPACE_STD
114
115#endif // _LIBCPP___FUNCTIONAL_RANGES_OPERATIONS_H