OpenKalman
viewable_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) 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_UNIFORM_TUPLE_LIKE_HPP
17 #define OPENKALMAN_COLLECTIONS_UNIFORM_TUPLE_LIKE_HPP
18 
22 
24 {
25  namespace detail
26  {
27  template<typename T>
28 #ifdef __cpp_concepts
29  concept move_constructible_object_or_lvalue_ref =
30 #else
31  inline constexpr bool move_constructible_object_or_lvalue_ref =
32 #endif
33  (stdex::move_constructible<T> and std::is_object_v<T>) or
34  std::is_lvalue_reference_v<T>;
35 
36 
37 #ifdef __cpp_concepts
38  template<typename T, typename = std::make_index_sequence<size_of_v<T>>>
39  struct has_viewable_elements : std::false_type {};
40 
41  template<typename T, std::size_t...i> requires
42  (... and move_constructible_object_or_lvalue_ref<collection_element_t<i, T>>)
43  struct has_viewable_elements<T, std::index_sequence<i...>> : std::true_type {};
44 #else
45  template<typename T, typename = std::make_index_sequence<size_of_v<T>>, typename = void>
46  struct has_viewable_elements_impl : std::false_type {};
47 
48  template<typename T, std::size_t...i>
49  struct has_viewable_elements_impl<T, std::index_sequence<i...>, std::enable_if_t<
50  (... and move_constructible_object_or_lvalue_ref<typename collection_element<i, T>::type>)>> : std::true_type {};
51 
52 
53  template<typename T, typename = void>
54  struct has_viewable_elements : std::false_type {};
55 
56  template<typename T>
57  struct has_viewable_elements<T, std::enable_if_t<uniformly_gettable<T>>> : has_viewable_elements_impl<T> {};
58 
59 
60  template<typename T, typename = void>
61  struct has_common_collection_type : std::false_type {};
62 
63  template<typename T>
64  struct has_common_collection_type<T, std::void_t<typename common_collection_type<T>::type>> : std::true_type {};
65 #endif
66  }
67 
68 
73  template<typename T>
74 #ifdef __cpp_concepts
75  concept viewable_tuple_like =
76  uniformly_gettable<T> and
77  (size_of_v<T> == 0 or requires { typename common_collection_type<T>::type; }) and
78  (std::is_lvalue_reference_v<T> or detail::has_viewable_elements<std::decay_t<T>>::value);
79 #else
80  inline constexpr bool viewable_tuple_like =
81  uniformly_gettable<T> and
83  (std::is_lvalue_reference_v<T> or detail::has_viewable_elements<std::decay_t<T>>::value);
84 #endif
85 
86 
87 }
88 
89 #endif
Namespace for collections.
Definition: collections.hpp:27
constexpr bool viewable_tuple_like
A uniformly_gettable object that has a common_collection_type and can be converted into a collection_...
Definition: viewable_tuple_like.hpp:80
Definition for collections::size_of.
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: viewable_tuple_like.hpp:54
constexpr bool fixed_value_compares_with
T has a fixed value that compares with N in a particular way based on parameter comp.
Definition: fixed_value_compares_with.hpp:74
The common type within a collection, if it exists.
Definition: common_collection_type.hpp:34
Definition for collections::uniformly_gettable.
Definition for collections::common_collection_type.