OpenKalman
make_fixed_square_adapter_like.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) 2022-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_MAKE_FIXED_SQUARE_ADAPTER_LIKE_HPP
18 #define OPENKALMAN_MAKE_FIXED_SQUARE_ADAPTER_LIKE_HPP
19 
23 
24 namespace OpenKalman::internal
25 {
26  namespace detail
27  {
28  template<typename...Ts>
29  using best_desc = std::decay_t<decltype(best_vector_space_descriptor(std::declval<Ts>()...))>;
30 
31 
32  template<typename...Ds, typename Arg, std::size_t...Ix>
33  constexpr decltype(auto) make_fixed_square_adapter_like_impl(Arg&& arg, std::index_sequence<Ix...>)
34  {
35  using B = best_desc<Ds..., vector_space_descriptor_of_t<Arg, Ix>...>;
36  using F = decltype(make_fixed_size_adapter<std::conditional_t<Ix >= 0, B, B>...>(std::declval<Arg&&>()));
37  constexpr bool better = (... or (dynamic_dimension<Arg, Ix> and not dynamic_dimension<F, Ix>));
38  if constexpr (better) return F {std::forward<Arg>(arg)};
39  else return std::forward<Arg>(arg);
40  }
41  } // namespace detail
42 
43 
49 #ifdef __cpp_concepts
50  template<coordinates::pattern D = coordinates::Axis, coordinates::pattern...Ds, square_shaped<Applicability::permitted> Arg> requires
51  (index_count_v<Arg> != dynamic_size) and (... and coordinates::compares_with<D, Ds, equal_to<>, Applicability::permitted>)
52 #else
53  template<typename...Ds, typename Arg, std::enable_if_t<
54  (... and coordinates::pattern<Ds>) and square_shaped<Arg, Applicability::permitted> and
55  (index_count_v<Arg> != dynamic_size) and (... and coordinates::compares_with<D, Ds, equal_to<>, Applicability::permitted>), int> = 0>
56 #endif
57  constexpr decltype(auto)
58  make_fixed_square_adapter_like(Arg&& arg)
59  {
60  return detail::make_fixed_square_adapter_like_impl<Ds...>(std::forward<Arg>(arg), std::make_index_sequence<index_count_v<Arg>>{});
61  }
62 
63 
64 } // namespace OpenKalman::internal
65 
66 #endif //OPENKALMAN_MAKE_FIXED_SQUARE_ADAPTER_LIKE_HPP
Definition for compares_with.
Definition of the Dimensions class.
Definition: tuple_reverse.hpp:103
Definition for coordinates::pattern.
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
Definition: basics.hpp:48