OpenKalman
owning_view.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_OWNING_VIEW_HPP
18 #define OPENKALMAN_COMPATIBILITY_VIEWS_OWNING_VIEW_HPP
19 
21 #include "view_interface.hpp"
22 
24 {
25 #ifdef __cpp_lib_ranges
26  using std::ranges::owning_view;
27 #else
28 
32  template<typename R>
33  struct owning_view : view_interface<owning_view<R>>
34  {
35  static_assert(std::is_object_v<std::remove_reference_t<R>> and std::is_move_constructible_v<std::remove_reference_t<R>> and
36  std::is_assignable_v<std::remove_reference_t<R>&, std::remove_reference_t<R>> and
38 
39 
43  template<bool Enable = true, std::enable_if_t<Enable and stdex::default_initializable<R>, int> = 0>
44  constexpr
46 
47 
51  constexpr
52  owning_view(owning_view&& other) = default;
53 
54 
58  explicit constexpr
59  owning_view(R&& t) : my_r {std::forward<R>(t)} {}
60 
61 
65  constexpr owning_view&
66  operator=(owning_view&& other) = default;
67 
68 
72  constexpr decltype(auto)
73  base() & { return my_r; }
74 
76  constexpr decltype(auto)
77  base() const & { return my_r; }
78 
80  constexpr decltype(auto)
81  base() && noexcept { return std::move(*this).my_r; }
82 
84  constexpr decltype(auto)
85  base() const && noexcept { return std::move(*this).my_r; }
86 
87 
91  constexpr auto begin() { return stdex::ranges::begin(my_r); }
92 
94  template<bool Enable = true, std::enable_if_t<Enable and range<const R>, int> = 0>
95  constexpr auto begin() const { return stdex::ranges::begin(my_r); }
96 
97 
101  constexpr auto end() { return stdex::ranges::end(my_r); }
102 
104  template<bool Enable = true, std::enable_if_t<Enable and range<const R>, int> = 0>
105  constexpr auto end() const { return stdex::ranges::end(my_r); }
106 
107 
111  template<typename Enable = void, typename = std::void_t<Enable, decltype(stdex::ranges::empty(std::declval<R>()))>>
112  constexpr auto empty() { return stdex::ranges::empty(my_r); }
113 
115  template<typename Enable = void, typename = std::void_t<Enable, decltype(stdex::ranges::empty(std::declval<const R>()))>>
116  constexpr auto empty() const { return stdex::ranges::empty(my_r); }
117 
118 
122  template<bool Enable = true, std::enable_if_t<Enable and sized_range<R>, int> = 0>
123  constexpr auto size() noexcept { return stdex::ranges::size(my_r); }
124 
126  template<bool Enable = true, std::enable_if_t<Enable and sized_range<const R>, int> = 0>
127  constexpr auto size() const noexcept { return stdex::ranges::size(my_r); }
128 
129  private:
130 
131  R my_r;
132 
133  };
134 
135 
136  template<typename R>
137  constexpr bool enable_borrowed_range<owning_view<R>> = enable_borrowed_range<R>;
138 
139 #endif
140 }
141 
142 #endif
decltype(auto) constexpr base() &
Get the base object.
Definition: owning_view.hpp:73
constexpr auto size() noexcept
The size of the object.
Definition: owning_view.hpp:123
constexpr auto end() const
Definition: owning_view.hpp:105
Definition: view_interface.hpp:32
constexpr auto end()
Definition: owning_view.hpp:101
Exposition-only definitions from teh c++ language standard.
constexpr owning_view & operator=(owning_view &&other)=default
Move assignment operator.
Definition: common.hpp:200
constexpr bool size
T is either an index representing a size, or unbounded_size_t, which indicates that the size is unbou...
Definition: size.hpp:65
constexpr auto begin()
Definition: owning_view.hpp:91
constexpr auto empty() const
Definition: owning_view.hpp:116
constexpr auto begin() const
Definition: owning_view.hpp:95
constexpr owning_view()
Default constructor.
Definition: owning_view.hpp:45
Whether the argument is a specialization of std::initializer_list.
Definition: exposition.hpp:76
constexpr auto size() const noexcept
Definition: owning_view.hpp:127
constexpr auto empty()
Indicates whether the view is empty.
Definition: owning_view.hpp:112
constexpr owning_view(R &&t)
Construct from a collection.
Definition: owning_view.hpp:59
Definition: owning_view.hpp:33