OpenKalman
functional.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2025 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_COMPATIBILITY_RANGES_FUNCTIONAL_HPP
17 #define OPENKALMAN_COMPATIBILITY_RANGES_FUNCTIONAL_HPP
18 
20 
22 {
23 #ifdef __cpp_lib_ranges
24  using std::ranges::equal_to;
25  using std::ranges::not_equal_to;
26  using std::ranges::greater;
27  using std::ranges::less;
28  using std::ranges::greater_equal;
29  using std::ranges::less_equal;
30 #else
31  struct equal_to
32  {
33  template<typename Tp, typename Up, std::enable_if_t<stdex::equality_comparable_with<Tp, Up>, int> = 0>
34  constexpr bool
35  operator()(Tp&& t, Up&& u) const noexcept(noexcept(std::declval<Tp>() == std::declval<Up>()))
36  {
37  return std::forward<Tp>(t) == std::forward<Up>(u);
38  }
39 
40  struct is_transparent;
41  };
42 
43 
44  struct not_equal_to
45  {
46  template<typename Tp, typename Up, std::enable_if_t<stdex::equality_comparable_with<Tp, Up>, int> = 0>
47  constexpr bool
48  operator()(Tp&& t, Up&& u) const noexcept(noexcept(std::declval<Up>() == std::declval<Tp>()))
49  {
50  return not equal_to{}(std::forward<Tp>(t), std::forward<Up>(u));
51  }
52 
53  struct is_transparent;
54  };
55 
56 
57  struct less
58  {
59  private:
60 
61  template<typename T, typename U, typename = void>
62  struct has_deduced_lt : std::false_type {};
63 
64  template<typename T, typename U>
65  struct has_deduced_lt<T, U, std::void_t<decltype(operator<(std::declval<T>(), std::declval<U>()))>> : std::true_type {};
66 
67  template<typename T, typename U, typename = void>
68  struct has_member_lt : std::false_type {};
69 
70  template<typename T, typename U>
71  struct has_member_lt<T, U, std::void_t<decltype(std::declval<T>().operator<(std::declval<U>()))>> : std::true_type {};
72 
73  public:
74 
75  template<typename Tp, typename Up, std::enable_if_t<stdex::totally_ordered_with<Tp, Up>, int> = 0>
76  constexpr bool
77  operator()(Tp&& t, Up&& u) const noexcept(noexcept(std::declval<Tp>() < std::declval<Up>()))
78  {
79  return std::forward<Tp>(t) < std::forward<Up>(u);
80  }
81 
82  struct is_transparent;
83  };
84 
85 
86  struct greater
87  {
88  template<typename Tp, typename Up, std::enable_if_t<stdex::totally_ordered_with<Tp, Up>, int> = 0>
89  constexpr bool
90  operator()(Tp&& t, Up&& u) const noexcept(noexcept(std::declval<Up>() < std::declval<Tp>()))
91  {
92  return less{}(std::forward<Up>(u), std::forward<Tp>(t));
93  }
94 
95  struct is_transparent;
96  };
97 
98 
100  {
101  template<typename Tp, typename Up, std::enable_if_t<stdex::totally_ordered_with<Tp, Up>, int> = 0>
102  constexpr bool
103  operator()(Tp&& t, Up&& u) const noexcept(noexcept(std::declval<Tp>() < std::declval<Up>()))
104  {
105  return not less{}(std::forward<Tp>(t), std::forward<Up>(u));
106  }
107 
108  struct is_transparent;
109  };
110 
111 
112  struct less_equal
113  {
114  template<typename Tp, typename Up, std::enable_if_t<stdex::totally_ordered_with<Tp, Up>, int> = 0>
115  constexpr bool
116  operator()(Tp&& t, Up&& u) const noexcept(noexcept(std::declval<Up>() < std::declval<Tp>()))
117  {
118  return not less{}(std::forward<Up>(u), std::forward<Tp>(t));
119  }
120 
121  struct is_transparent;
122  };
123 
124 #endif
125 
126 }
127 
128 #endif
Definition: functional.hpp:57
Definitions relating to c+++20+ comparisons.
Definition: functional.hpp:31
Definition: common.hpp:200
Definition: functional.hpp:112
Definition: functional.hpp:99
Definition: functional.hpp:44
Definition: functional.hpp:86