Horizon
Loading...
Searching...
No Matches
3rd_party
range-v3
range
v3
view
generate.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
14
#ifndef RANGES_V3_VIEW_GENERATE_HPP
15
#define RANGES_V3_VIEW_GENERATE_HPP
16
17
#include <type_traits>
18
#include <utility>
19
20
#include <
meta/meta.hpp
>
21
22
#include <
range/v3/range_fwd.hpp
>
23
24
#include <
range/v3/functional/invoke.hpp
>
25
#include <
range/v3/iterator/unreachable_sentinel.hpp
>
26
#include <
range/v3/range/access.hpp
>
27
#include <
range/v3/range/primitives.hpp
>
28
#include <
range/v3/range/traits.hpp
>
29
#include <
range/v3/utility/optional.hpp
>
30
#include <
range/v3/utility/semiregular_box.hpp
>
31
#include <range/v3/utility/static_const.hpp>
32
#include <
range/v3/view/facade.hpp
>
33
34
#include <range/v3/detail/prologue.hpp>
35
36
namespace
ranges
37
{
40
template
<
typename
G>
41
struct
generate_view
:
view_facade
<generate_view<G>, infinite>
42
{
43
private
:
44
friend
range_access;
45
using
result_t = invoke_result_t<G &>;
46
semiregular_box_t<G> gen_;
47
detail::non_propagating_cache<result_t> val_;
48
struct
cursor
49
{
50
private
:
51
generate_view
*
view_
;
52
53
public
:
54
cursor() =
default
;
55
explicit
cursor(
generate_view
* view)
56
:
view_
(view)
57
{}
58
result_t && read()
const
59
{
60
if
(!
view_
->val_)
61
view_
->val_.emplace(
view_
->gen_());
62
return
static_cast<
result_t &&
>
(
static_cast<
result_t &
>
(*
view_
->val_));
63
}
64
void
next()
65
{
66
if
(
view_
->val_)
67
view_
->val_.reset();
68
else
69
static_cast<
void
>
(
view_
->gen_());
70
}
71
};
72
cursor begin_cursor()
73
{
74
return
cursor{
this
};
75
}
76
unreachable_sentinel_t
end_cursor()
const
77
{
78
return
{};
79
}
80
81
public
:
82
generate_view
() =
default
;
83
explicit
generate_view
(G g)
84
: gen_(std::move(g))
85
{}
86
result_t & cached()
87
{
88
return
*val_;
89
}
90
};
91
92
namespace
views
93
{
94
struct
generate_fn
95
{
96
template
(
typename
G)(
97
requires
invocable<G &>
AND copy_constructible<G> AND
98
std::is_object<detail::decay_t<invoke_result_t<G &>>>::value AND
99
constructible_from<detail::decay_t<invoke_result_t<G &>>,
100
invoke_result_t<G &>> AND
101
assignable_from<detail::decay_t<invoke_result_t<G &>> &,
102
invoke_result_t<G &>>)
103
generate_view<G>
operator()(G g)
const
104
{
105
return
generate_view<G>
{std::move(g)};
106
}
107
};
108
111
RANGES_INLINE_VARIABLE(
generate_fn
, generate)
112
}
// namespace views
114
}
// namespace ranges
115
116
#include <range/v3/detail/epilogue.hpp>
117
#include <range/v3/detail/satisfy_boost_range.hpp>
118
RANGES_SATISFY_BOOST_RANGE(
::ranges::generate_view
)
119
120
#endif
ranges::invocable
The invocable concept.
ranges::view_
The view_ concept.
facade.hpp
invoke.hpp
meta.hpp
Tiny meta-programming library.
optional.hpp
primitives.hpp
access.hpp
traits.hpp
range_fwd.hpp
semiregular_box.hpp
ranges::generate_view
Definition
generate.hpp:42
ranges::unreachable_sentinel_t
Definition
unreachable_sentinel.hpp:27
ranges::view_facade
A utility for constructing a view from a (derived) type that implements begin and end cursors.
Definition
facade.hpp:66
ranges::views::generate_fn
Definition
generate.hpp:95
unreachable_sentinel.hpp
Generated by
1.9.8