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_COMPATIBILITY_VIEWS_ALL_HPP
18 #define OPENKALMAN_COMPATIBILITY_VIEWS_ALL_HPP
19 
20 #include <type_traits>
22 #include "view-concepts.hpp"
24 #include "ref_view.hpp"
25 #include "owning_view.hpp"
26 
28 {
29 #ifdef __cpp_lib_ranges
32 #else
33  namespace detail
34  {
35  template<typename R, typename = void, typename = void>
36  struct can_ref_view : std::false_type {};
37 
38  template<typename R>
39  struct can_ref_view<R, std::enable_if_t<std::is_object_v<stdex::remove_cvref_t<R>> and range<stdex::remove_cvref_t<R>>>,
40  std::void_t<decltype(ref_view {std::declval<R>()})>> : std::true_type {};
41 
42 
43  struct all_closure : range_adaptor_closure<all_closure>
44  {
45  template<typename R, std::enable_if_t<viewable_range<R>, int> = 0>
46  constexpr auto
47  operator() [[nodiscard]] (R&& r) const
48  {
49  if constexpr (view<std::decay_t<R>>)
50  return static_cast<std::decay_t<R>>(std::forward<R>(r));
51  else if constexpr (can_ref_view<R>::value)
52  return ref_view {std::forward<R>(r)};
53  else
54  return owning_view {std::forward<R>(r)};
55  }
56  };
57  }
58 
59 
64  inline constexpr detail::all_closure all;
65 
66 
71  template<typename R, std::enable_if_t<viewable_range<R>, int> = 0>
72  using all_t = decltype(all(std::declval<R>()));
73 
74 #endif
75 }
76 
77 #endif
decltype(all(std::declval< R >())) all_t
Equivalent to std::ranges::views::all_t.
Definition: all.hpp:72
Definition: all.hpp:27
Definitions relating to the availability of c++ language features.
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:72
Definition: range_adaptor_closure.hpp:34
Definition: ref_view.hpp:33
decltype(all(std::declval< R >())) all_t
Calculates the suitable collection_view type of a viewable_collection type.
Definition: all.hpp:84
Definition: owning_view.hpp:33