Horizon
generate.hpp
Go to the documentation of this file.
1 // 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_ALGORITHM_GENERATE_HPP
14 #define RANGES_V3_ALGORITHM_GENERATE_HPP
15 
16 #include <utility>
17 
18 #include <range/v3/range_fwd.hpp>
19 
20 #include <range/v3/algorithm/result_types.hpp>
28 #include <range/v3/utility/static_const.hpp>
29 
30 #include <range/v3/detail/prologue.hpp>
31 
32 namespace ranges
33 {
36  template<typename O, typename F>
37  using generate_result = detail::out_fun_result<O, F>;
38 
39  RANGES_FUNC_BEGIN(generate)
40 
41 
42  template(typename O, typename S, typename F)(
43  requires invocable<F &> AND output_iterator<O, invoke_result_t<F &>> AND
44  sentinel_for<S, O>)
45  constexpr generate_result<O, F> RANGES_FUNC(generate)(O first, S last, F fun) //
46  {
47  for(; first != last; ++first)
48  *first = invoke(fun);
49  return {detail::move(first), detail::move(fun)};
50  }
51 
53  template(typename Rng, typename F)(
54  requires invocable<F &> AND output_range<Rng, invoke_result_t<F &>>)
55  constexpr generate_result<borrowed_iterator_t<Rng>, F> //
56  RANGES_FUNC(generate)(Rng && rng, F fun)
57  {
58  return {(*this)(begin(rng), end(rng), ref(fun)).out, detail::move(fun)};
59  }
60 
61  RANGES_FUNC_END(generate)
62 
63  namespace cpp20
64  {
65  using ranges::generate;
66  using ranges::generate_result;
67  } // namespace cpp20
69 } // namespace ranges
70 
71 #include <range/v3/detail/epilogue.hpp>
72 
73 #endif
template(typename Rng, typename F)(requires invocable< F & > AND output_range< Rng
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept invocable
\concept invocable
Definition: concepts.hpp:48
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept output_iterator
\concept output_iterator
Definition: concepts.hpp:347
CPP_concept output_range
\concept output_range
Definition: concepts.hpp:91
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251