OpenKalman
make_fixed_size_adapter.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-2023 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_SIZE_ADAPTER_HPP
18 #define OPENKALMAN_MAKE_FIXED_SIZE_ADAPTER_HPP
19 
20 namespace OpenKalman::internal
21 {
22  namespace detail
23  {
24  template<typename DTup, typename Arg, std::size_t...Ix>
25  constexpr decltype(auto)
26  make_fixed_size_adapter_impl(Arg&& arg, std::index_sequence<Ix...> seq)
27  {
28  return FixedSizeAdapter<Arg,
29  std::tuple<decltype(most_fixed_pattern(get_pattern_collection(std::declval<Arg>(), Ix),
30  std::get<Ix>(std::declval<DTup>())))...>> {std::forward<Arg>(arg)};
31  }
32  }
33 
34 
42 #ifdef __cpp_concepts
43  template<pattern_collection Descriptors, compatible_with_vector_space_descriptor_collection<Descriptors> Arg>
44 #else
45  template<typename Descriptors, typename Arg, std::enable_if_t<pattern_collection<Descriptors> and
46  compatible_with_vector_space_descriptor_collection<Arg, Descriptors>, int> = 0>
47 #endif
48  constexpr decltype(auto)
49  make_fixed_size_adapter(Arg&& arg)
50  {
51  if constexpr (fixed_size_adapter<Arg>)
52  {
53  return make_fixed_size_adapter<Descriptors>(nested_object(std::forward<Arg>(arg)));
54  }
55  else if constexpr (internal::less_fixed_than<Arg, Descriptors>)
56  {
57  using DTup = std::decay_t<decltype(coordinates::internal::strip_1D_tail(std::declval<Descriptors>()))>;
58  std::make_index_sequence<collections::size_of_v<DTup>> seq {};
59  return detail::make_fixed_size_adapter_impl<DTup>(std::forward<Arg>(arg), seq);
60  }
61  else
62  {
63  return std::forward<Arg>(arg);
64  }
65  }
66 
67 
71 #ifdef __cpp_concepts
72  template<coordinates::pattern...Ds, compatible_with_vector_space_descriptor_collection<std::tuple<Ds...>> Arg>
73 #else
74  template<typename...Ds, typename Arg, std::enable_if_t<(... and coordinates::pattern<Ds>) and
75  compatible_with_vector_space_descriptor_collection<Arg, std::tuple<Ds...>>, int> = 0>
76 #endif
77  constexpr decltype(auto)
78  make_fixed_size_adapter(Arg&& arg)
79  {
80  return make_fixed_size_adapter<std::tuple<Ds...>>(std::forward<Arg>(arg));
81  }
82 
83 
87 #ifdef __cpp_concepts
88  template<indexible Arg, pattern_collection Descriptors>
89  requires compatible_with_vector_space_descriptor_collection<Arg, Descriptors>
90 #else
91  template<typename Arg, typename Descriptors, std::enable_if_t<indexible<Arg> and pattern_collection<Descriptors> and
92  compatible_with_vector_space_descriptor_collection<Arg, Descriptors>, int> = 0>
93 #endif
94  constexpr decltype(auto)
95  make_fixed_size_adapter(Arg&& arg, Descriptors&&)
96  {
97  return make_fixed_size_adapter<Descriptors>(std::forward<Arg>(arg));
98  }
99 
100 
101 }
102 
103 #endif
constexpr bool pattern
An object describing the set of coordinates associated with a tensor index.
Definition: pattern.hpp:31
decltype(auto) constexpr make_fixed_size_adapter(Arg &&arg)
Make the best possible FixedSizeAdapter, if applicable, based on a set of vector space descriptors...
Definition: make_fixed_size_adapter.hpp:49
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:35
Definition: basics.hpp:48