fill_n.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_FILL_N_H
  9. #define _LIBCPP___ALGORITHM_FILL_N_H
  10. #include <__config>
  11. #include <__iterator/iterator_traits.h>
  12. #include <__utility/convert_to_integral.h>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. // fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
  18. template <class _OutputIterator, class _Size, class _Tp>
  19. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
  20. __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
  21. for (; __n > 0; ++__first, (void)--__n)
  22. *__first = __value;
  23. return __first;
  24. }
  25. template <class _OutputIterator, class _Size, class _Tp>
  26. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
  27. fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
  28. return std::__fill_n(__first, std::__convert_to_integral(__n), __value);
  29. }
  30. _LIBCPP_END_NAMESPACE_STD
  31. #endif // _LIBCPP___ALGORITHM_FILL_N_H