47 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ALGORITHM_GENERATE_N_H10#define _LIBCPP___ALGORITHM_GENERATE_N_H11 12#include <__algorithm/for_each_n.h>13#include <__config>14#include <__functional/identity.h>15#include <__utility/forward.h>16#include <__utility/move.h>17 18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)19# pragma GCC system_header20#endif21 22_LIBCPP_PUSH_MACROS23#include <__undef_macros>24 25_LIBCPP_BEGIN_NAMESPACE_STD26 27template <class _OutputIterator, class _Size, class _Generator>28inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator29__generate_n(_OutputIterator __first, _Size __orig_n, _Generator& __gen) {30 using __iter_ref = decltype(*__first);31 __identity __proj;32 auto __f = [&](__iter_ref __element) { std::forward<__iter_ref>(__element) = __gen(); };33 return std::__for_each_n(std::move(__first), __orig_n, __f, __proj);34}35 36template <class _OutputIterator, class _Size, class _Generator>37inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator38generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) {39 return std::__generate_n(std::move(__first), __orig_n, __gen);40}41 42_LIBCPP_END_NAMESPACE_STD43 44_LIBCPP_POP_MACROS45 46#endif // _LIBCPP___ALGORITHM_GENERATE_N_H47