OpenKalman
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) 2019-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_COORDINATE_COMPARES_WITH_HPP
17 #define OPENKALMAN_COORDINATE_COMPARES_WITH_HPP
18 
19 #include <type_traits>
27 
29 {
30  namespace detail
31  {
32  template<typename C>
33  struct comp_adapter
34  {
35  template<typename T, typename U>
36  constexpr bool operator()(const T& t, const U& u) const
37  {
38  if constexpr (euclidean_pattern<T> and euclidean_pattern<U>)
39  return std::decay_t<C>{}(values::to_number(get_dimension(t)), values::to_number(get_dimension(u)));
40  else if constexpr (collections::collection<T> and collections::collection<U>)
41  return std::decay_t<C>{}(comparison_view<T>{t}, u);
42  else
43  return std::decay_t<C>{}(t, u);
44  }
45  };
46 
47 
48 #ifdef __cpp_concepts
49  template<typename T>
50  concept euclidean_status_is_fixed = values::fixed<decltype(coordinates::get_is_euclidean(std::declval<T>()))>;
51 #else
52  template<typename T, typename U, typename Comparison, Applicability applicability, typename = void>
53  struct comparison_invocable : std::false_type {};
54 
55  template<typename T, typename U, typename Comparison, Applicability applicability>
56  struct comparison_invocable<T, U, Comparison, applicability, std::enable_if_t<
57  std::is_convertible<decltype(detail::comp_adapter<Comparison>{}(std::declval<T>(), std::declval<U>())), bool>::value>>
58  : std::true_type {};
59 
60 
61  template<typename T, typename U, typename Comparison, typename = void>
62  struct compares_with_guaranteed : std::false_type {};
63 
64  template<typename T, typename U, typename Comparison>
65  struct compares_with_guaranteed<T, U, Comparison, std::enable_if_t<
66  std::bool_constant<detail::comp_adapter<Comparison>{}(std::decay_t<T>{}, std::decay_t<U>{})>::value>>
67  : std::true_type {};
68 
69 
70  template<typename T, typename U, typename Comparison, Applicability applicability, typename = void>
71  struct compares_with_permitted : std::false_type {};
72 
73  template<typename T, typename U, typename Comparison, Applicability applicability>
74  struct compares_with_permitted<T, U, Comparison, applicability, std::enable_if_t<
75  (values::fixed<decltype(coordinates::get_is_euclidean(std::declval<T>()))> !=
76  values::fixed<decltype(coordinates::get_is_euclidean(std::declval<U>()))>)>>
77  : std::true_type {};
78 #endif
79  } // namespace detail
80 
81 
95  template<typename T, typename U, typename Comparison = equal_to<>, Applicability applicability = Applicability::guaranteed>
96 #ifdef __cpp_concepts
97  concept compares_with = pattern<T> and pattern<U> and std::default_initializable<Comparison> and
98  std::convertible_to<decltype(detail::comp_adapter<Comparison>{}(std::declval<T>(), std::declval<U>())), bool> and
99  ((fixed_pattern<T> and fixed_pattern<U> and std::bool_constant<detail::comp_adapter<Comparison>{}(std::decay_t<T>{}, std::decay_t<U>{})>::value) or
100  (applicability == Applicability::permitted and (dynamic_pattern<T> or dynamic_pattern<U>) and
101  (euclidean_pattern<T> == euclidean_pattern<U> or detail::euclidean_status_is_fixed<T> != detail::euclidean_status_is_fixed<U>)));
102 #else
103  constexpr bool compares_with = pattern<T> and pattern<U> and std::is_default_constructible_v<Comparison> and
105  ((fixed_pattern<T> and fixed_pattern<U> and detail::compares_with_guaranteed<T, U, Comparison>::value) or
106  (applicability == Applicability::permitted and (dynamic_pattern<T> or dynamic_pattern<U>) and
107  (euclidean_pattern<T> == euclidean_pattern<U> or detail::compares_with_permitted<T, U, Comparison, applicability>::value)));
108 #endif
109 
110 
111 } // namespace OpenKalman::coordinates
112 
113 #endif //OPENKALMAN_COORDINATE_COMPARES_WITH_HPP
constexpr bool compares_with
Specifies that a set of coordinates::pattern objects may be equivalent based on what is known at comp...
Definition: compares_with.hpp:103
Definition for coordinates::dynamic_pattern.
Comparison operators for coordinates::pattern objects.
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
Definition for coordinates::pattern.
constexpr auto to_number(Arg arg)
Convert any values::value to a values::number.
Definition: to_number.hpp:34
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:55
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
Definition: compares_with.hpp:28
Definition of equal_to.
Definition: comparison.hpp:47
Global definitions for OpenKalman.
Definition: compares_with.hpp:33