Horizon
Loading...
Searching...
No Matches
for_each.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_FOR_EACH_HPP
15#define RANGES_V3_VIEW_FOR_EACH_HPP
16
17#include <utility>
18
19#include <meta/meta.hpp>
20
22
25#include <range/v3/utility/static_const.hpp>
26#include <range/v3/view/all.hpp>
33
34#include <range/v3/detail/prologue.hpp>
35
36namespace ranges
37{
40
41 namespace views
42 {
47 {
48 template(typename Rng, typename Fun)(
50 joinable_range<transform_view<all_t<Rng>, Fun>>)
51 constexpr auto operator()(Rng && rng, Fun fun) const
52 {
53 return join(transform(static_cast<Rng &&>(rng), std::move(fun)));
54 }
55 };
56
58 {
59 using for_each_base_fn::operator();
60
61 template<typename Fun>
62 constexpr auto operator()(Fun fun) const
63 {
64 return make_view_closure(bind_back(for_each_base_fn{}, std::move(fun)));
65 }
66 };
67
69 RANGES_INLINE_VARIABLE(for_each_fn, for_each)
70 } // namespace views
71
72 struct yield_fn
73 {
74 template(typename V)(
75 requires copy_constructible<V>)
76 single_view<V> operator()(V v) const
77 {
78 return views::single(std::move(v));
79 }
80 };
81
83 RANGES_INLINE_VARIABLE(yield_fn, yield)
84
86 {
87 template(typename Rng)(
88 requires view_<Rng>)
89 Rng operator()(Rng rng) const
90 {
91 return rng;
92 }
93 };
94
96 RANGES_INLINE_VARIABLE(yield_from_fn, yield_from)
97
99 {
100 template<typename V>
101 repeat_n_view<V> operator()(bool b, V v) const
102 {
103 return views::repeat_n(std::move(v), b ? 1 : 0);
104 }
105 };
106
108 RANGES_INLINE_VARIABLE(yield_if_fn, yield_if)
109
111 {
112 template(typename F)(
113 requires invocable<F &>)
114 generate_n_view<F> operator()(bool b, F f) const
115 {
116 return views::generate_n(std::move(f), b ? 1 : 0);
117 }
118 };
119
121 RANGES_INLINE_VARIABLE(lazy_yield_if_fn, lazy_yield_if)
123
125 template(typename Rng, typename Fun)(
127 input_range<invoke_result_t<Fun &, range_reference_t<Rng>>>)
128 auto
129 operator>>=(Rng && rng, Fun fun)
130 {
131 return views::for_each(static_cast<Rng &&>(rng), std::move(fun));
132 }
134} // namespace ranges
135
136#include <range/v3/detail/epilogue.hpp>
137
138#endif
The input_range concept.
The invocable concept.
The view_ concept.
The viewable_range concept.
The transformable_range concept.
Tiny meta-programming library.
Definition generate_n.hpp:41
Definition for_each.hpp:111
Definition repeat_n.hpp:43
Definition single.hpp:41
Definition transform.hpp:201
Lazily applies an unary function to each element in the source range that returns another range (poss...
Definition for_each.hpp:47
Definition for_each.hpp:58
Definition for_each.hpp:73
Definition for_each.hpp:86
Definition for_each.hpp:99