OpenKalman
gettable.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 
16 #ifndef OPENKALMAN_COLLECTIONS_GETTABLE_HPP
17 #define OPENKALMAN_COLLECTIONS_GETTABLE_HPP
18 
19 #include <tuple>
21 #include "sized.hpp"
23 
25 {
26 #ifndef __cpp_concepts
27  namespace detail
28  {
29  template<std::size_t i, typename T, typename = void, typename = void>
30  struct gettable_impl : std::false_type {};
31 
32  template<std::size_t i, typename T>
33  struct gettable_impl<i, T, std::enable_if_t<sized<T> and i < size_of_v<T>>, std::void_t<
34  typename std::tuple_element<i, std::decay_t<T>>::type,
35  decltype(internal::generalized_std_get<i>(std::declval<T&>()))>> : std::true_type {};
36 
37  template<std::size_t i, typename T>
38  struct gettable_impl<i, T, std::enable_if_t<not sized<T>>, std::void_t<
39  typename std::tuple_element<i, std::decay_t<T>>::type,
40  decltype(internal::generalized_std_get<i>(std::declval<T&>()))>> : std::true_type {};
41 
42  } // namespace detail
43 #endif
44 
45 
51  template<std::size_t i, typename T>
52 #ifdef __cpp_concepts
53  concept gettable =
54  (not sized<T> or i < size_of_v<T>) and
55  requires { typename std::tuple_element<i, std::decay_t<T>>::type;
56  internal::generalized_std_get<i>(std::declval<T&>()); };
57 #else
58  constexpr bool gettable = detail::gettable_impl<i, T>::value;
59 #endif
60 
61 
62 } // namespace OpenKalman::collections
63 
64 #endif //OPENKALMAN_COLLECTIONS_GETTABLE_HPP
Namespace for collections.
Definition: collections.hpp:27
constexpr bool gettable
T has an element i that is accessible by a get(...) function.
Definition: gettable.hpp:58
Definition for collections::size_of.
Definition for collections::sized.
Definitions relating to the availability of c++ language features.