OpenKalman
tuple_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) 2021-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_TUPLE_LIKE_HPP
17 #define OPENKALMAN_COLLECTIONS_TUPLE_LIKE_HPP
18 
19 #include <tuple>
20 #include "basics/basics.hpp"
21 #include "uniformly_gettable.hpp"
22 
24 {
25 #if not defined(__cpp_concepts) and __cpp_generic_lambdas < 201707L
26  namespace detail
27  {
28  template<std::size_t i, typename T, typename = void>
29  struct has_tuple_element_impl : std::false_type {};
30 
31  template<std::size_t i, typename T>
32  struct has_tuple_element_impl<i, T, std::void_t<typename std::tuple_element<i, T>::type>> : std::true_type {};
33 
34 
35  template<typename T, typename = std::make_index_sequence<collections::size_of_v<T>>>
36  struct is_tuple_like_impl : std::false_type {};
37 
38  template<typename T, std::size_t...i>
39  struct is_tuple_like_impl<T, std::index_sequence<i...>>
40  : std::bool_constant<(... and (gettable<i, T> and has_tuple_element_impl<i, T>::value))> {};
41 
42 
43  template<typename T, typename = void>
44  struct is_tuple_like : std::false_type {};
45 
46  template<typename T>
47  struct is_tuple_like<T, std::void_t<decltype(std::tuple_size<T>::value)>> : is_tuple_like_impl<T> {};
48  }
49 #endif
50 
51 
57  template<typename T>
58 #if defined(__cpp_concepts) and __cpp_generic_lambdas >= 201707L
59  concept tuple_like = requires {
60  std::tuple_size<std::decay_t<T>>::value;
61  requires []<std::size_t...i>(std::index_sequence<i...>) {
62  return (... and (gettable<i, T> and requires { typename std::tuple_element<i, std::decay_t<T>>::type; }));
63  } (std::make_index_sequence<size_of_v<T>>{});
64  };
65 #else
66  constexpr bool tuple_like = detail::is_tuple_like<std::decay_t<T>>::value;
67 #endif
68 
69 
70 }
71 
72 #endif
Namespace for collections.
Definition: collections.hpp:27
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: trait_backports.hpp:64
Basic definitions for OpenKalman as a whole.
Definition for collections::uniformly_gettable.
constexpr bool tuple_like
T is a non-empty tuple, pair, array, or other type that acts like a tuple.
Definition: tuple_like.hpp:66