OpenKalman
comparison.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 
17 #ifndef OPENKALMAN_COORDINATES_VIEWS_COMPARISON_HPP
18 #define OPENKALMAN_COORDINATES_VIEWS_COMPARISON_HPP
19 
26 
28 {
42 #ifdef __cpp_lib_ranges
43  template<descriptor_collection T>
44 #else
45  template<typename T>
46 #endif
47  struct comparison_view : collections::collection_view_interface<comparison_view<T>>
48  {
49 #ifdef __cpp_concepts
50  constexpr comparison_view() requires std::default_initializable<T> = default;
51 #else
52  template<typename aT = T, std::enable_if_t<std::is_default_constructible_v<aT>, int> = 0>
53  constexpr comparison_view() {}
54 #endif
55 
56 
57 #ifdef __cpp_concepts
58  template<typename Arg> requires std::constructible_from<T, Arg&&>
59 #else
60  template<typename Arg, std::enable_if_t<std::is_constructible_v<T, Arg&&>, int> = 0>
61 #endif
62  explicit constexpr comparison_view(Arg&& arg) : t {std::forward<Arg>(arg)} {}
63 
64 
65 #ifdef __cpp_explicit_this_parameter
66  template<values::index I> requires (values::fixed<I> or sized_random_access_range<T>) and
67  (values::dynamic<I> or collections::dimension_of_v<T> == dynamic_size or (values::fixed_number_of_v<I> < collections::dimension_of_v<T>))
68  constexpr decltype(auto)
69  operator[](this auto&& self, I i)
70  {
71  return internal::get_descriptor_collection_element(std::forward<decltype(self)>(self).t, std::move(i));
72  }
73 #else
74  template<typename I, std::enable_if_t<values::index<I> and (values::fixed<I> or sized_random_access_range<T>), int> = 0>
75  constexpr decltype(auto)
76  operator[](I i) const &
77  {
78  if constexpr(values::fixed<I> and collections::dimension_of_v<T> != dynamic_size) static_assert(values::fixed_number_of_v<I> < collections::dimension_of_v<T>);
79  return internal::get_descriptor_collection_element(t, std::move(i));
80  }
81 
82 
83  template<typename I, std::enable_if_t<values::index<I> and (values::fixed<I> or sized_random_access_range<T>), int> = 0>
84  constexpr decltype(auto)
85  operator[](I i) &&
86  {
87  if constexpr(values::fixed<I> and collections::dimension_of_v<T> != dynamic_size) static_assert(values::fixed_number_of_v<I> < collections::dimension_of_v<T>);
88  return internal::get_descriptor_collection_element(std::move(*this).t, std::move(i));
89  }
90 #endif
91 
92 
93 #ifdef __cpp_concepts
94  constexpr values::index auto size() const
95 #else
96  constexpr auto size() const
97 #endif
98  {
99  return get_size(t);
100  }
101 
102  private:
103 
104  T t;
105  };
106 
107 
111  template<typename Arg>
113 
114 } // namespace OpenKalman::coordinates
115 
116 
117 #ifndef __cpp_concepts
118 namespace std
119 {
120  template<typename T>
121  struct tuple_size<OpenKalman::coordinates::comparison_view<T>> : tuple_size<OpenKalman::collection_view_interface<OpenKalman::coordinates::comparison_view<T>>> {};
122 
123  template<size_t i, typename T>
124  struct tuple_element<i, OpenKalman::coordinates::comparison_view<T>> : tuple_element<i, OpenKalman::collection_view_interface<OpenKalman::coordinates::comparison_view<T>>> {};
125 } // namespace std
126 #endif
127 
128 
130 {
131  namespace detail
132  {
134 #if __cpp_lib_ranges >= 202202L
135  : std::ranges::range_adaptor_closure<comparison_impl>
136 #endif
137  {
138 #ifdef __cpp_concepts
139  template<descriptor_collection R>
140 #else
141  template<typename R, std::enable_if_t<descriptor_collection<R>, int> = 0>
142 #endif
143  constexpr auto
144  operator() [[nodiscard]] (R&& r) const { return comparison_view<R> {std::forward<R>(r)}; }
145  };
146  }
147 
148 
156 
157 
158 } // namespace OpenKalman::coordinates
159 
160 
161 #endif //OPENKALMAN_COORDINATES_VIEWS_COMPARISON_HPP
Definition for values::index.
Definition for collections::sized_random_access_range.
constexpr detail::comparison_impl comparison
a RangeAdapterObject associated with comparison_view.
Definition: comparison.hpp:155
Definition: tuple_reverse.hpp:103
Definition for collections::get_size.
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition: compares_with.hpp:28
Definition: comparison.hpp:129
constexpr bool index
T is an index value.
Definition: index.hpp:56
Definition for ::fixed.
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
Definition: comparison.hpp:47
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:191
Definition for coordinates::descriptor_collection.