Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:53

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_N_HPP
0014 #define RANGES_V3_ALGORITHM_GENERATE_N_HPP
0015 
0016 #include <tuple>
0017 #include <utility>
0018 
0019 #include <range/v3/range_fwd.hpp>
0020 
0021 #include <range/v3/algorithm/result_types.hpp>
0022 #include <range/v3/functional/invoke.hpp>
0023 #include <range/v3/iterator/concepts.hpp>
0024 #include <range/v3/iterator/operations.hpp>
0025 #include <range/v3/range/access.hpp>
0026 #include <range/v3/range/concepts.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_n_result = detail::out_fun_result<O, F>;
0038 
0039     RANGES_FUNC_BEGIN(generate_n)
0040 
0041         /// \brief function template \c generate_n
0042         template(typename O, typename F)(
0043             requires invocable<F &> AND output_iterator<O, invoke_result_t<F &>>)
0044         constexpr generate_n_result<O, F> //
0045         RANGES_FUNC(generate_n)(O first, iter_difference_t<O> n, F fun)
0046         {
0047             RANGES_EXPECT(n >= 0);
0048             auto norig = n;
0049             auto b = uncounted(first);
0050             for(; 0 != n; ++b, --n)
0051                 *b = invoke(fun);
0052             return {recounted(first, b, norig), detail::move(fun)};
0053         }
0054 
0055     RANGES_FUNC_END(generate_n)
0056 
0057     namespace cpp20
0058     {
0059         using ranges::generate_n;
0060         using ranges::generate_n_result;
0061     } // namespace cpp20
0062     // @}
0063 } // namespace ranges
0064 
0065 #include <range/v3/detail/epilogue.hpp>
0066 
0067 #endif