Debian Codegraph @

3rd_party/range-v3/range/v3/algorithm/for_each.hpp

raw
1 /// \file
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_ALGORITHM_FOR_EACH_HPP
14 #define RANGES_V3_ALGORITHM_FOR_EACH_HPP
15
16 #include <functional>
17
18 #include <range/v3/range_fwd.hpp>
19
20 #include <range/v3/algorithm/result_types.hpp>
21 #include <range/v3/functional/identity.hpp>
22 #include <range/v3/functional/invoke.hpp>
23 #include <range/v3/functional/reference_wrapper.hpp>
24 #include <range/v3/iterator/traits.hpp>
25 #include <range/v3/range/access.hpp>
26 #include <range/v3/range/concepts.hpp>
27 #include <range/v3/range/dangling.hpp>
28 #include <range/v3/range/traits.hpp>
29 #include <range/v3/utility/static_const.hpp>
30
31 #include <range/v3/detail/prologue.hpp>
32
33 namespace ranges
34 {
35 /// \addtogroup group-algorithms
36 /// @{
37 template<typename I, typename F>
38 using for_each_result = detail::in_fun_result<I, F>;
39
40 RANGES_FUNC_BEGIN(for_each)
41
42 /// \brief function template \c for_each
43 template(typename I, typename S, typename F, typename P = identity)(
44 requires input_iterator<I> AND sentinel_for<S, I> AND
45 indirectly_unary_invocable<F, projected<I, P>>)
46 constexpr for_each_result<I, F> RANGES_FUNC(for_each)(I first, S last, F fun, P proj = P{})
47 {
48 for(; first != last; ++first)
49 {
50 invoke(fun, invoke(proj, *first));
51 }
52 return {detail::move(first), detail::move(fun)};
53 }
54
55 /// \overload
56 template(typename Rng, typename F, typename P = identity)(
57 requires input_range<Rng> AND
58 indirectly_unary_invocable<F, projected<iterator_t<Rng>, P>>)
59 constexpr for_each_result<borrowed_iterator_t<Rng>, F> //
60 RANGES_FUNC(for_each)(Rng && rng, F fun, P proj = P{})
61 {
62 return {(*this)(begin(rng), end(rng), ref(fun), detail::move(proj)).in,
63 detail::move(fun)};
64 }
65
66 RANGES_FUNC_END(for_each)
67
68 namespace cpp20
69 {
70 using ranges::for_each;
71 using ranges::for_each_result;
72 } // namespace cpp20
73 /// @}
74 } // namespace ranges
75
76 #include <range/v3/detail/epilogue.hpp>
77
78 #endif