VCCC  2024.05
VisualCamp Common C++ library
as_const_view.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/15/24.
3 //
4 
5 #ifndef VCCC_RANGES_VIEWS_AS_CONST_VIEW_HPP
6 #define VCCC_RANGES_VIEWS_AS_CONST_VIEW_HPP
7 
8 #include <utility>
9 
11 #include "vccc/__ranges/cbegin.hpp"
15 #include "vccc/__ranges/range.hpp"
17 #include "vccc/__ranges/view.hpp"
18 
19 namespace vccc {
20 namespace ranges {
21 
24 
25 template<typename V>
26 class as_const_view : public view_interface<as_const_view<V>> {
27  public:
28  static_assert(view<V>::value, "Constraints not satisfied");
29  static_assert(input_range<V>::value, "Constraints not satisfied");
30 
31  as_const_view() = default;
32 
33  constexpr explicit as_const_view(V base)
34  : base_(std::move(base)) {}
35 
37  constexpr V base() const& {
38  return base_;
39  }
40 
41  constexpr V base() && {
42  return std::move(base_);
43  }
44 
46  constexpr auto begin() {
47  return vccc::ranges::cbegin(base_);
48  }
49 
51  constexpr auto begin() const {
52  return vccc::ranges::cbegin(base_);
53  }
54 
56  constexpr auto end() {
57  return vccc::ranges::cend(base_);
58  }
59 
61  constexpr auto end() const {
62  return vccc::ranges::cend(base_);
63  }
64 
66  constexpr auto size() {
67  return vccc::ranges::size(base_);
68  }
69 
71  constexpr auto size() const {
72  return vccc::ranges::size(base_);
73  }
74 
75  private:
76  V base_;
77 };
78 
79 #if __cplusplus >= 201703L
80 
81 template<typename R>
82 as_const_view(R&&) -> as_const_view<views::all_t<R>>;
83 
84 #endif
85 
86 template<typename T>
88 
90 
91 } // namespace ranges
92 } // namespace vccc
93 
94 #endif // VCCC_RANGES_VIEWS_AS_CONST_VIEW_HPP
Definition: as_const_view.hpp:26
constexpr V base() const &
Definition: as_const_view.hpp:37
constexpr auto size() const
Definition: as_const_view.hpp:71
constexpr auto size()
Definition: as_const_view.hpp:66
constexpr V base() &&
Definition: as_const_view.hpp:41
constexpr auto end()
Definition: as_const_view.hpp:56
constexpr auto end() const
Definition: as_const_view.hpp:61
constexpr auto begin() const
Definition: as_const_view.hpp:51
constexpr auto begin()
Definition: as_const_view.hpp:46
constexpr as_const_view(V base)
Definition: as_const_view.hpp:33
helper class template for defining a view, using the curiously recurring template pattern
Definition: view_interface.hpp:78
constexpr VCCC_INLINE_OR_STATIC detail::cbegin_niebloid cbegin
returns an iterator to the beginning of a read-only range
Definition: cbegin.hpp:46
constexpr VCCC_INLINE_OR_STATIC detail::size_niebloid size
returns the size of a container or array
Definition: size.hpp:145
constexpr VCCC_INLINE_OR_STATIC detail::cend_niebloid cend
returns a sentinel indicating the end of a read-only range
Definition: cend.hpp:46
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: enable_borrowed_range.hpp:17
specifies a range whose iterator type satisfies input_iterator
Definition: input_range.hpp:46
specifies that a range is a view, that is, it has constant time copy/move/assignment
Definition: view.hpp:31