fill_n.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <type_traits>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. template <class _OutputIterator, class _Size, class _Tp>
  18. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
  19. _OutputIterator
  20. __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
  21. {
  22. for (; __n > 0; ++__first, (void) --__n)
  23. *__first = __value;
  24. return __first;
  25. }
  26. template <class _OutputIterator, class _Size, class _Tp>
  27. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
  28. _OutputIterator
  29. fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
  30. {
  31. return _VSTD::__fill_n(__first, _VSTD::__convert_to_integral(__n), __value);
  32. }
  33. _LIBCPP_END_NAMESPACE_STD
  34. #endif // _LIBCPP___ALGORITHM_FILL_N_H