Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:54:38

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2014-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_ALGORITHM_GENERATE_HPP
0014 #define RANGES_V3_ALGORITHM_GENERATE_HPP
0015 
0016 #include <utility>
0017 
0018 #include <range/v3/range_fwd.hpp>
0019 
0020 #include <range/v3/algorithm/result_types.hpp>
0021 #include <range/v3/functional/invoke.hpp>
0022 #include <range/v3/functional/reference_wrapper.hpp>
0023 #include <range/v3/iterator/concepts.hpp>
0024 #include <range/v3/range/access.hpp>
0025 #include <range/v3/range/concepts.hpp>
0026 #include <range/v3/range/dangling.hpp>
0027 #include <range/v3/range/traits.hpp>
0028 #include <range/v3/utility/static_const.hpp>
0029 
0030 #include <range/v3/detail/prologue.hpp>
0031 
0032 namespace ranges
0033 {
0034     /// \addtogroup group-algorithms
0035     /// @{
0036     template<typename O, typename F>
0037     using generate_result = detail::out_fun_result<O, F>;
0038 
0039     RANGES_FUNC_BEGIN(generate)
0040 
0041         /// \brief function template \c generate_n
0042         template(typename O, typename S, typename F)(
0043             requires invocable<F &> AND output_iterator<O, invoke_result_t<F &>> AND
0044             sentinel_for<S, O>)
0045         constexpr generate_result<O, F> RANGES_FUNC(generate)(O first, S last, F fun) //
0046         {
0047             for(; first != last; ++first)
0048                 *first = invoke(fun);
0049             return {detail::move(first), detail::move(fun)};
0050         }
0051 
0052         /// \overload
0053         template(typename Rng, typename F)(
0054             requires invocable<F &> AND output_range<Rng, invoke_result_t<F &>>)
0055         constexpr generate_result<borrowed_iterator_t<Rng>, F> //
0056         RANGES_FUNC(generate)(Rng && rng, F fun)
0057         {
0058             return {(*this)(begin(rng), end(rng), ref(fun)).out, detail::move(fun)};
0059         }
0060 
0061     RANGES_FUNC_END(generate)
0062 
0063     namespace cpp20
0064     {
0065         using ranges::generate;
0066         using ranges::generate_result;
0067     } // namespace cpp20
0068     /// @}
0069 } // namespace ranges
0070 
0071 #include <range/v3/detail/epilogue.hpp>
0072 
0073 #endif