ranges_fill.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. _LIBCPP_PUSH_MACROS
  20. #include <__undef_macros>
  21. #if _LIBCPP_STD_VER >= 20
  22. _LIBCPP_BEGIN_NAMESPACE_STD
  23. namespace ranges {
  24. namespace __fill {
  25. struct __fn {
  26. template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
  27. _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
  28. if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
  29. return ranges::fill_n(__first, __last - __first, __value);
  30. } else {
  31. for (; __first != __last; ++__first)
  32. *__first = __value;
  33. return __first;
  34. }
  35. }
  36. template <class _Type, output_range<const _Type&> _Range>
  37. _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const {
  38. return (*this)(ranges::begin(__range), ranges::end(__range), __value);
  39. }
  40. };
  41. } // namespace __fill
  42. inline namespace __cpo {
  43. inline constexpr auto fill = __fill::__fn{};
  44. } // namespace __cpo
  45. } // namespace ranges
  46. _LIBCPP_END_NAMESPACE_STD
  47. #endif // _LIBCPP_STD_VER >= 20
  48. _LIBCPP_POP_MACROS
  49. #endif // _LIBCPP___ALGORITHM_RANGES_FILL_H