fill_n.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  20. _OutputIterator
  21. __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
  22. {
  23. for (; __n > 0; ++__first, (void) --__n)
  24. *__first = __value;
  25. return __first;
  26. }
  27. template <class _OutputIterator, class _Size, class _Tp>
  28. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  29. _OutputIterator
  30. fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
  31. {
  32. return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value);
  33. }
  34. _LIBCPP_END_NAMESPACE_STD
  35. #endif // _LIBCPP___ALGORITHM_FILL_N_H