OpenKalman
fill_components.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 
16 #ifndef OPENKALMAN_FILL_COMPONENTS_HPP
17 #define OPENKALMAN_FILL_COMPONENTS_HPP
18 
20 
21 namespace OpenKalman
22 {
23  namespace detail
24  {
25  // \todo this is nonsensical right now, but can be converted to a generic function for copying elements
26  template<std::size_t rank = 0, typename U, typename Indices, typename S>
27  static constexpr void
28  fill_components_impl(U& u, const Indices& indices, const S& s)
29  {
30  if constexpr (rank < std::rank_v<T>)
31  {
32  auto i = values::to_value_type(collections::get_element(indices, std::integral_constant<std::size_t, rank>{}));
33  set_component_impl<rank + 1>(u[i], indices, s);
34  }
35  else
36  {
37  u = s;
38  }
39  }
40  }
41 
42 
53 #ifdef __cpp_concepts
54  template<internal::layout_mapping_policy layout = stdex::layout_right, indexible Arg, values::number ... S> requires
55  (std::same_as<layout, stdex::layout_right> or std::same_as<layout, stdex::layout_left>) and
56  internal::may_hold_components<Arg, S...> and
57  (sizeof...(S) == 0 or interface::fill_components_defined_for<Arg, layout, std::add_lvalue_reference_t<Arg>, S...>)
58  inline Arg&&
59 #else
60  template<typename layout layout = stdex::layout_right, typename Arg, typename...S, std::enable_if_t<
61  indexible<Arg> and (values::number<S> and ...) and
62  (std::same_as<layout, stdex::layout_right> or std::same_as<layout, stdex::layout_left>) and
63  internal::may_hold_components<Arg, S...> and
64  (sizeof...(S) == 0 or interface::fill_components_defined_for<Arg, layout, std::add_lvalue_reference_t<Arg>, S...>), int> = 0>
65  inline Arg&&
66 #endif
67  fill_components(Arg&& arg, S...s)
68  {
69  if constexpr (sizeof...(S) == 0)
70  {
71  return std::forward<Arg>(arg);
72  }
73  else
74  {
75  using Scalar = element_type_of_t<Arg>;
77  Trait::template fill_components<layout>(arg, static_cast<const Scalar>(s)...);
78  return std::forward<Arg>(arg);
79  }
80  // \todo add a facility for when the interface is not defined
81  }
82 
83 
84 }
85 
86 #endif
Definition for layout_mapping_policy.
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
decltype(auto) constexpr to_value_type(Arg &&arg)
Convert, if necessary, a fixed or dynamic value to its underlying base type.
Definition: to_value_type.hpp:28
constexpr bool number
T is a numerical field type.
Definition: number.hpp:41
The root namespace for OpenKalman.
Definition: basics.hpp:34
An interface to various routines from the linear algebra library associated with indexible object T...
Definition: library_interface.hpp:42
Arg && fill_components(Arg &&arg, S...s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: fill_components.hpp:67
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:122
typename element_type_of< T >::type element_type_of_t
helper template for element_type_of.
Definition: element_type_of.hpp:54