File indexing completed on 2025-12-16 10:27:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RANGES_V3_ALGORITHM_FOR_EACH_HPP
0014 #define RANGES_V3_ALGORITHM_FOR_EACH_HPP
0015
0016 #include <functional>
0017
0018 #include <range/v3/range_fwd.hpp>
0019
0020 #include <range/v3/algorithm/result_types.hpp>
0021 #include <range/v3/functional/identity.hpp>
0022 #include <range/v3/functional/invoke.hpp>
0023 #include <range/v3/functional/reference_wrapper.hpp>
0024 #include <range/v3/iterator/traits.hpp>
0025 #include <range/v3/range/access.hpp>
0026 #include <range/v3/range/concepts.hpp>
0027 #include <range/v3/range/dangling.hpp>
0028 #include <range/v3/range/traits.hpp>
0029 #include <range/v3/utility/static_const.hpp>
0030
0031 #include <range/v3/detail/prologue.hpp>
0032
0033 namespace ranges
0034 {
0035
0036
0037 template<typename I, typename F>
0038 using for_each_result = detail::in_fun_result<I, F>;
0039
0040 RANGES_FUNC_BEGIN(for_each)
0041
0042
0043 template(typename I, typename S, typename F, typename P = identity)(
0044 requires input_iterator<I> AND sentinel_for<S, I> AND
0045 indirectly_unary_invocable<F, projected<I, P>>)
0046 constexpr for_each_result<I, F> RANGES_FUNC(for_each)(I first, S last, F fun, P proj = P{})
0047 {
0048 for(; first != last; ++first)
0049 {
0050 invoke(fun, invoke(proj, *first));
0051 }
0052 return {detail::move(first), detail::move(fun)};
0053 }
0054
0055
0056 template(typename Rng, typename F, typename P = identity)(
0057 requires input_range<Rng> AND
0058 indirectly_unary_invocable<F, projected<iterator_t<Rng>, P>>)
0059 constexpr for_each_result<borrowed_iterator_t<Rng>, F>
0060 RANGES_FUNC(for_each)(Rng && rng, F fun, P proj = P{})
0061 {
0062 return {(*this)(begin(rng), end(rng), ref(fun), detail::move(proj)).in,
0063 detail::move(fun)};
0064 }
0065
0066 RANGES_FUNC_END(for_each)
0067
0068 namespace cpp20
0069 {
0070 using ranges::for_each;
0071 using ranges::for_each_result;
0072 }
0073
0074 }
0075
0076 #include <range/v3/detail/epilogue.hpp>
0077
0078 #endif