OpenKalman
all.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_COLLECTIONS_VIEWS_ALL_HPP
18 #define OPENKALMAN_COLLECTIONS_VIEWS_ALL_HPP
19 
20 #ifdef __cpp_lib_ranges
21 #include <ranges>
22 #else
26 #endif
28 #include "from_tuple.hpp"
29 #include "to_tuple.hpp"
30 
32 {
33  namespace detail
34  {
35  struct all_closure
36 #if __cpp_lib_ranges >= 202202L
37  : std::ranges::range_adaptor_closure<all_closure>
38 #else
40 #endif
41  {
42 #ifdef __cpp_concepts
43  template<viewable_collection R>
44  constexpr collection_view auto
45 #else
46  template<typename R, std::enable_if_t<viewable_collection<R>, int> = 0>
47  constexpr auto
48 #endif
49  operator() [[nodiscard]] (R&& r) const
50  {
51  using namespace std;
52  if constexpr (collection_view<R>)
53  {
54  return static_cast<std::decay_t<R>>(std::forward<R>(r));
55  }
56  else if constexpr (uniform_tuple_like<R>)
57  {
58  if constexpr (size_of_v<R> == 1)
59  #ifdef __cpp_lib_ranges
60  return std::ranges::views::single(OpenKalman::internal::generalized_std_get<0>(std::forward<R>(r)));
61  #else
62  return ranges::views::single(OpenKalman::internal::generalized_std_get<0>(std::forward<R>(r)));
63  #endif
64  else return from_tuple {std::forward<R>(r)};
65  }
66  else // std::ranges::random_access_range<T> and std::ranges::viewable_range<T>
67  {
68  return to_tuple {std::forward<R>(r)};
69  }
70  }
71  };
72  }
73 
74 
85  inline constexpr detail::all_closure all;
86 
87 
92 #ifdef __cpp_concepts
93  template<viewable_collection R>
94 #else
95  template<typename R, std::enable_if_t<viewable_collection<R>, int> = 0>
96 #endif
97  using all_t = decltype(all(std::declval<R>()));
98 
99 }
100 
101 
102 #endif //OPENKALMAN_COLLECTIONS_VIEWS_ALL_HPP
A collection_view created from a std::ranges::random_access_range that is a std::ranges::viewable_ran...
Definition: to_tuple.hpp:139
Definition: tuple_reverse.hpp:103
constexpr detail::all_closure all
a std::ranges::range_adaptor_closure which returns a view to all members of its collection argument...
Definition: all.hpp:85
constexpr bool collection_view
A view to a collection which is also a std::ranges:view.
Definition: collection_view.hpp:36
A collection_view created from a uniform_tuple_like object.
Definition: from_tuple.hpp:75
Namespace for generalized views.
Definition: collections.hpp:33
Definition for collections::to_tuple.
Definitions implementing features of the c++ ranges library for compatibility.
Definition for collections::from_tuple.
Definition for collections::viewable_collection.
decltype(all(std::declval< R >())) all_t
Calculates the suitable collection_view type of a viewable_collection type.
Definition: all.hpp:97