/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ALGORITHM_TRANSFORM_HPP #define RANGES_V3_ALGORITHM_TRANSFORM_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-algorithms /// @{ template using unary_transform_result = detail::in_out_result; template using binary_transform_result = detail::in1_in2_out_result; RANGES_BEGIN_NIEBLOID(transform) // Single-range variant /// \brief function template \c transform template auto RANGES_FUN_NIEBLOID(transform)( I first, S last, O out, F fun, P proj = P{}) // ->CPP_ret(unary_transform_result)( // requires input_iterator && sentinel_for && weakly_incrementable && copy_constructible && writable>>) { for(; first != last; ++first, ++out) *out = invoke(fun, invoke(proj, *first)); return {first, out}; } /// \overload template auto RANGES_FUN_NIEBLOID(transform)(Rng && rng, O out, F fun, P proj = P{}) // ->CPP_ret(unary_transform_result, O>)( // requires input_range && weakly_incrementable && copy_constructible && writable, P>>>) { return (*this)( begin(rng), end(rng), std::move(out), std::move(fun), std::move(proj)); } // Double-range variant, 4-iterator version /// \overload template auto RANGES_FUN_NIEBLOID(transform)(I0 begin0, S0 end0, I1 begin1, S1 end1, O out, F fun, P0 proj0 = P0{}, P1 proj1 = P1{}) // ->CPP_ret(binary_transform_result)( // requires input_iterator && sentinel_for && input_iterator && sentinel_for && weakly_incrementable && copy_constructible && writable, projected>>) { for(; begin0 != end0 && begin1 != end1; ++begin0, ++begin1, ++out) *out = invoke(fun, invoke(proj0, *begin0), invoke(proj1, *begin1)); return {begin0, begin1, out}; } /// \overload template auto RANGES_FUN_NIEBLOID(transform)( Rng0 && rng0, Rng1 && rng1, O out, F fun, P0 proj0 = P0{}, P1 proj1 = P1{}) // ->CPP_ret(binary_transform_result, safe_iterator_t, O>)( // requires input_range && input_range && weakly_incrementable && copy_constructible && writable, P0>, projected, P1>>>) { return (*this)(begin(rng0), end(rng0), begin(rng1), end(rng1), std::move(out), std::move(fun), std::move(proj0), std::move(proj1)); } // Double-range variant, 3-iterator version /// \overload template RANGES_DEPRECATED( "Use the variant of ranges::transform that takes an upper bound " "for both input ranges") auto RANGES_FUN_NIEBLOID(transform)(I0 begin0, S0 end0, I1 begin1, O out, F fun, P0 proj0 = P0{}, P1 proj1 = P1{}) // ->CPP_ret(binary_transform_result)( // requires input_iterator && sentinel_for && input_iterator && weakly_incrementable && copy_constructible && writable, projected>>) { return (*this)(std::move(begin0), std::move(end0), std::move(begin1), unreachable, std::move(out), std::move(fun), std::move(proj0), std::move(proj1)); } /// \overload template RANGES_DEPRECATED( "Use the variant of ranges::transform that takes an upper bound " "for both input ranges") auto RANGES_FUN_NIEBLOID(transform)(Rng0 && rng0, I1Ref && begin1, O out, F fun, P0 proj0 = P0{}, P1 proj1 = P1{}) // ->CPP_ret( binary_transform_result, uncvref_t, O>)( // requires input_range && input_iterator> && weakly_incrementable && copy_constructible && writable, P0>, projected, P1>>>) { return (*this)(begin(rng0), end(rng0), static_cast(begin1), unreachable, std::move(out), std::move(fun), std::move(proj0), std::move(proj1)); } RANGES_END_NIEBLOID(transform) namespace cpp20 { using ranges::binary_transform_result; using ranges::transform; using ranges::unary_transform_result; } // namespace cpp20 /// @} } // namespace ranges #endif // include guard