OpenKalman
size_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_SIZE_COMPARES_WITH_HPP
17 #define OPENKALMAN_VALUES_SIZE_COMPARES_WITH_HPP
18 
19 #include "basics/basics.hpp"
20 #include "values/constants.hpp"
21 #include "fixed.hpp"
22 #include "size.hpp"
25 
26 namespace OpenKalman::values
27 {
28  namespace detail
29  {
30  template<auto comp, bool op_is_and = false, typename...Ords>
31  constexpr bool
32  do_comps(Ords...ords)
33  {
34  if constexpr (op_is_and) return (... and stdex::invoke(comp, ords));
35  else return (... or stdex::invoke(comp, ords));
36  }
37 
38 
39  template<typename T, typename U, auto comp, applicability a>
40  constexpr bool
41  size_compares_with_impl()
42  {
43  constexpr bool unbt = not index<T>;
44  constexpr bool unbu = not index<U>;
45  constexpr bool ft = fixed_value_compares_with<T, stdex::dynamic_extent, &stdex::is_neq>;
46  constexpr bool fu = fixed_value_compares_with<U, stdex::dynamic_extent, &stdex::is_neq>;
47 
48  if constexpr (unbt and unbu)
49  {
50  return do_comps<comp>(stdex::partial_ordering::equivalent);
51  }
52  else if constexpr (unbu)
53  {
54  return do_comps<comp>(stdex::partial_ordering::less);
55  }
56  else if constexpr (unbt)
57  {
58  return do_comps<comp>(stdex::partial_ordering::greater);
59  }
60  else if constexpr (ft and fu)
61  {
62 #ifdef __cpp_impl_three_way_comparison
63  return stdex::invoke(comp, fixed_value_of_v<T> <=> fixed_value_of_v<U>);
64 #else
65  return stdex::invoke(comp, stdex::compare_three_way{}(fixed_value_of_v<T>, fixed_value_of_v<U>));
66 #endif
67  }
68  else if constexpr (ft)
69  {
70  if constexpr (fixed_value_compares_with<T, 0>)
71  return do_comps<comp, a == applicability::guaranteed>(stdex::partial_ordering::less, stdex::partial_ordering::equivalent);
72  else
73  return a == applicability::permitted;
74  }
75  else if constexpr (fu)
76  {
77  if constexpr (fixed_value_compares_with<U, 0>)
78  return do_comps<comp, a == applicability::guaranteed>(stdex::partial_ordering::greater, stdex::partial_ordering::equivalent);
79  else
80  return a == applicability::permitted;
81  }
82  else
83  {
84  return a == applicability::permitted;
85  }
86  }
87  }
88 
89 
94  template<typename T, typename U, auto comp = &stdex::is_eq, applicability a = applicability::guaranteed>
95 #ifdef __cpp_concepts
96  concept size_compares_with =
97 #else
98  constexpr bool size_compares_with =
99 #endif
100  size<T> and
101  size<U> and
102  detail::size_compares_with_impl<T, U, comp, a>();
103 
104 }
105 
106 #endif
Definition for values::size.
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
constexpr bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
Definition for values::abs.
Definition: fixed-constants.hpp:23
Definition for values::fixed_value_of.
Definition for ::fixed.
constexpr auto compare_three_way(A &&a, B &&b, const Comparison &c={})
Compare two coordinates::pattern objects lexicographically.
Definition: compare_three_way.hpp:142
Global constants relating to collections.
Basic definitions for OpenKalman as a whole.
Definition for ::fixed_value_compares_with.