OpenKalman
fixed_value_compares_with.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_VALUES_FIXED_VALUE_COMPARES_WITH_HPP
17 #define OPENKALMAN_VALUES_FIXED_VALUE_COMPARES_WITH_HPP
18 
19 #include "basics/basics.hpp"
20 #include "fixed.hpp"
23 
24 namespace OpenKalman::values
25 {
26  namespace detail
27  {
28  template<auto N, unsigned int epsilon_factor>
30  {
31  template<typename T>
32  constexpr stdex::partial_ordering
33  operator() [[nodiscard]] (T&& t) const
34  {
35  constexpr auto n = static_cast<typename value_type_of<T>::type>(N);
36  if constexpr (epsilon_factor == 0U)
37  {
38  return stdex::compare_three_way{}(std::forward<T>(t), n);
39  }
40  else
41  {
42  if (internal::near<epsilon_factor>(t, n)) return stdex::partial_ordering::equivalent;
43  return stdex::compare_three_way{}(std::forward<T>(t), n);
44  }
45  }
46  };
47 
48 
49 #if not defined(__cpp_concepts) or not defined(__cpp_impl_three_way_comparison)
50  template<typename T, auto N, auto comp, unsigned int epsilon_factor, typename = void>
51  struct fixed_value_compares_with_impl : std::false_type {};
52 
53  template<typename T, auto N, auto comp, unsigned int epsilon_factor>
54  struct fixed_value_compares_with_impl<T, N, comp, epsilon_factor, std::enable_if_t<
55  stdex::invoke(comp, detail::compare_three_way_near<N, epsilon_factor>{}(fixed_value_of<T>::value))>>
56  : std::true_type {};
57 #endif
58  }
59 
60 
68  template<typename T, auto N, auto comp = &stdex::is_eq, unsigned int epsilon_factor = 0U>
69 #if defined(__cpp_concepts) and defined(__cpp_impl_three_way_comparison)
71  fixed<T> and
72  stdex::invoke(comp, detail::compare_three_way_near<N, epsilon_factor>{}(fixed_value_of_v<T>));
73 #else
75 #endif
76 
77 }
78 
79 #endif
Definition: comparison.hpp:104
Obtain the underlying value type associated with a value.
Definition: value_type_of.hpp:32
Definition: fixed_value_compares_with.hpp:29
Definition: comparison.hpp:176
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition for values::abs.
Definition: fixed-constants.hpp:23
Definition for values::fixed_value_of.
constexpr bool fixed_value_compares_with
T has a fixed value that compares with N in a particular way based on parameter comp.
Definition: fixed_value_compares_with.hpp:74
Definition for ::fixed.
Basic definitions for OpenKalman as a whole.