OpenKalman
view-concepts.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_VIEW_CONCEPTS_HPP
18 #define OPENKALMAN_COMPATIBILITY_VIEWS_VIEW_CONCEPTS_HPP
19 
20 #ifndef __cpp_lib_ranges
21 
25 #include "view_interface.hpp"
26 
27 namespace OpenKalman::ranges
28 {
29  // ---
30  // view, enable_view, view_base
31  // ---
32 
33  struct view_base {};
34 
35  namespace detail
36  {
37  template<typename T, typename U, std::enable_if_t<not std::is_same_v<T, view_interface<U>>, int> = 0>
38  void is_derived_from_view_interface_test(const T&, const view_interface<U>&); // no need to define
39 
40 
41  template<typename T, typename = void>
42  struct is_derived_from_view_interface : std::false_type {};
43 
44  template<typename T>
46  std::void_t<decltype(is_derived_from_view_interface_test(std::declval<T>(), std::declval<T>()))>> : std::true_type {};
47  }
48 
49 
50  template<class T>
51  inline constexpr bool enable_view =
52  (std::is_base_of_v<view_base, T> and std::is_convertible_v<const volatile T&, const volatile view_base&>) or
54 
55 
56  template<typename T>
57  inline constexpr bool view = range<T> and movable<T> and enable_view<T>;
58 
59 
60  // ---
61  // viewable_range
62  // ---
63 
64  namespace detail
65  {
66  template<typename T>
67  struct is_initializer_list : std::false_type {};
68 
69  template<typename T>
70  struct is_initializer_list<std::initializer_list<T>> : std::true_type {};
71  }
72 
73 
74  template<typename T>
75  constexpr bool viewable_range = ranges::range<T> and
76  ((view<remove_cvref_t<T>> and std::is_constructible_v<remove_cvref_t<T>, T>) or
77  (not view<remove_cvref_t<T>> and
78  (std::is_lvalue_reference_v<T> or
79  (movable<std::remove_reference_t<T>> and not OpenKalman::internal::is_initializer_list<remove_cvref_t<T>>::value))));
80 
81 }
82 
83 
84 #endif
85 
86 #endif //OPENKALMAN_COMPATIBILITY_VIEWS_VIEW_CONCEPTS_HPP
Definition: view_interface.hpp:32
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
Definition: range-access.hpp:25
Definition: view-concepts.hpp:67
Definitions relating to the availability of c++ language features.
Definitions implementing features of the c++ ranges library for compatibility.
Definition: view-concepts.hpp:33
Whether the argument is a specialization of std::initializer_list.
Definition: global-definitions.hpp:165
Global definitions for OpenKalman.