Horizon
Loading...
Searching...
No Matches
counted.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2014-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13#ifndef RANGES_V3_VIEW_COUNTED_HPP
14#define RANGES_V3_VIEW_COUNTED_HPP
15
16#include <utility>
17
19
24#include <range/v3/utility/static_const.hpp>
27
28#include <range/v3/detail/prologue.hpp>
29
30namespace ranges
31{
34 template<typename I>
35 struct counted_view : view_interface<counted_view<I>, finite>
36 {
37 private:
38 friend range_access;
39 I it_;
40 iter_difference_t<I> n_;
41
42 public:
43 counted_view() = default;
44 counted_view(I it, iter_difference_t<I> n)
45 : it_(it)
46 , n_(n)
47 {
48 RANGES_EXPECT(0 <= n_);
49 }
50 counted_iterator<I> begin() const
51 {
52 return make_counted_iterator(it_, n_);
53 }
54 default_sentinel_t end() const
55 {
56 return {};
57 }
58 auto size() const
59 {
60 return static_cast<detail::iter_size_t<I>>(n_);
61 }
62 };
63
64 template<typename I>
65 RANGES_INLINE_VAR constexpr bool enable_borrowed_range<counted_view<I>> = true;
66
67#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
68 template<typename I>
69 counted_view(I, iter_difference_t<I>)
71#endif
72
73 namespace views
74 {
76 {
77 template(typename I)(
79 subrange<counted_iterator<I>, default_sentinel_t> //
80 operator()(I it, iter_difference_t<I> n) const
81 {
82 return {make_counted_iterator(std::move(it), n), default_sentinel};
83 }
84 template(typename I)(
86 subrange<I> operator()(I it, iter_difference_t<I> n) const
87 {
88 return {it, it + n};
89 }
90 };
91
93 {
94 template(typename I)(
96 counted_view<I> operator()(I it, iter_difference_t<I> n) const
97 {
98 return {std::move(it), n};
99 }
100 template(typename I)(
102 subrange<I> operator()(I it, iter_difference_t<I> n) const
103 {
104 return {it, it + n};
105 }
106 };
107
110 RANGES_INLINE_VARIABLE(counted_fn, counted)
111 } // namespace views
112
113 namespace cpp20
114 {
115 namespace views
116 {
117 RANGES_INLINE_VARIABLE(ranges::views::cpp20_counted_fn, counted)
118 }
119 } // namespace cpp20
121} // namespace ranges
122
123#include <range/v3/detail/epilogue.hpp>
124#include <range/v3/detail/satisfy_boost_range.hpp>
125RANGES_SATISFY_BOOST_RANGE(::ranges::counted_view)
126
127#endif
The input_or_output_iterator concept.
The random_access_iterator concept.
Definition counted.hpp:36
Definition default_sentinel.hpp:26
Definition subrange.hpp:196
Definition interface.hpp:129
Definition counted.hpp:93
Definition counted.hpp:76