ranges_fill.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_RANGES_FILL_H
  9. #define _LIBCPP___ALGORITHM_RANGES_FILL_H
  10. #include <__algorithm/ranges_fill_n.h>
  11. #include <__config>
  12. #include <__iterator/concepts.h>
  13. #include <__ranges/access.h>
  14. #include <__ranges/concepts.h>
  15. #include <__ranges/dangling.h>
  16. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  17. # pragma GCC system_header
  18. #endif
  19. #if _LIBCPP_STD_VER >= 20
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. namespace ranges {
  22. namespace __fill {
  23. struct __fn {
  24. template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
  25. _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
  26. if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
  27. return ranges::fill_n(__first, __last - __first, __value);
  28. } else {
  29. for (; __first != __last; ++__first)
  30. *__first = __value;
  31. return __first;
  32. }
  33. }
  34. template <class _Type, output_range<const _Type&> _Range>
  35. _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const {
  36. return (*this)(ranges::begin(__range), ranges::end(__range), __value);
  37. }
  38. };
  39. } // namespace __fill
  40. inline namespace __cpo {
  41. inline constexpr auto fill = __fill::__fn{};
  42. } // namespace __cpo
  43. } // namespace ranges
  44. _LIBCPP_END_NAMESPACE_STD
  45. #endif // _LIBCPP_STD_VER >= 20
  46. #endif // _LIBCPP___ALGORITHM_RANGES_FILL_H