OpenKalman
tuple_fill_view.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_TUPLE_FILL_VIEW_HPP
18 #define OPENKALMAN_TUPLE_FILL_VIEW_HPP
19 
20 #include <type_traits>
21 #include <tuple>
22 
24 {
31  template<std::size_t N, typename T>
33  {
34 #ifdef __cpp_concepts
35  constexpr repeat_tuple_view() requires std::default_initializable<T> = default;
36 #else
37  template<typename aT = T, std::enable_if_t<std::is_default_constructible_v<aT>, int> = 0>
38  constexpr repeat_tuple_view() {};
39 #endif
40 
41 
42 #ifdef __cpp_concepts
43  template<typename Arg> requires std::constructible_from<T, Arg&&>
44 #else
45  template<typename Arg, std::enable_if_t<std::is_constructible_v<T, Arg&&>, int> = 0>
46 #endif
47  explicit constexpr repeat_tuple_view(Arg&& arg) : t {std::forward<Arg>(arg)} {}
48 
49 
53  constexpr T value() const { return t; }
54 
55 
59 #ifdef __cpp_concepts
60  template<std::size_t i> requires (i < N)
61 #else
62  template<std::size_t i, std::enable_if_t<i < N, int> = 0>
63 #endif
64  friend constexpr T
65  get(const repeat_tuple_view& v)
66  {
67  return v.t;
68  }
69 
70 
74 #ifdef __cpp_concepts
75  template<size_t i> requires (i < N)
76 #else
77  template<size_t i, std::enable_if_t<i < N, int> = 0>
78 #endif
79  friend constexpr T
80  get(repeat_tuple_view&& v)
81  {
82  return std::move(v).t;
83  }
84 
85  private:
86 
87  T t;
88  };
89 
90 }
91 
92 
93 namespace std
94 {
95  template<std::size_t N, typename T>
96  struct tuple_size<OpenKalman::collections::internal::repeat_tuple_view<N, T>> : std::integral_constant<size_t, N> {};
97 
98 
99  template<std::size_t i, std::size_t N, typename T>
100  struct tuple_element<i, OpenKalman::collections::internal::repeat_tuple_view<N, T>>
101  {
102  static_assert(i < N);
103  using type = T;
104  };
105 } // namespace std
106 
107 
108 #endif //OPENKALMAN_TUPLE_FILL_VIEW_HPP
constexpr T value() const
Definition: tuple_fill_view.hpp:53
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition: tuple_like_to_tuple.hpp:24