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 
23 #ifndef OPENKALMAN_COMPATIBILITY_VIEWS_ALL_HPP
24 #define OPENKALMAN_COMPATIBILITY_VIEWS_ALL_HPP
25 
26 #ifndef __cpp_lib_ranges
27 
28 #include <type_traits>
30 #include "view-concepts.hpp"
32 #include "ref_view.hpp"
33 #include "owning_view.hpp"
34 
36 {
37  namespace detail
38  {
39  template<typename R, typename = void, typename = void>
40  struct can_ref_view : std::false_type {};
41 
42  template<typename R>
43  struct can_ref_view<R, std::enable_if_t<std::is_object_v<remove_cvref_t<R>> and range<remove_cvref_t<R>>>,
44  std::void_t<decltype(ref_view {std::declval<R>()})>> : std::true_type {};
45 
46 
47  struct all_closure : range_adaptor_closure<all_closure>
48  {
49  template<typename R, std::enable_if_t<viewable_range<R>, int> = 0>
50  constexpr auto
51  operator() [[nodiscard]] (R&& r) const
52  {
53  if constexpr (view<std::decay_t<R>>)
54  return static_cast<std::decay_t<R>>(std::forward<R>(r));
55  else if constexpr (can_ref_view<R>::value)
56  return ref_view {std::forward<R>(r)};
57  else
58  return owning_view {std::forward<R>(r)};
59  }
60  };
61  }
62 
63 
68  inline constexpr detail::all_closure all;
69 
70 
75  template<typename R, std::enable_if_t<viewable_range<R>, int> = 0>
76  using all_t = decltype(all(std::declval<R>()));
77 
78 }
79 
80 
81 #endif
82 
83 #endif //OPENKALMAN_COMPATIBILITY_VIEWS_ALL_HPP
Definition: tuple_reverse.hpp:103
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:85
Definition: ref_view.hpp:32
Definition: range_adaptor_closure.hpp:35
Definition: owning_view.hpp:32
decltype(all(std::declval< R >())) all_t
Equivalent to std::ranges::views::all_t.
Definition: all.hpp:76
Definition: all.hpp:35