| 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 | |
| 9 | #ifndef _LIBCPP___ALGORITHM_RANGES_FILL_H |
| 10 | #define _LIBCPP___ALGORITHM_RANGES_FILL_H |
| 11 | |
| 12 | #include <__algorithm/fill.h> |
| 13 | #include <__algorithm/fill_n.h> |
| 14 | #include <__config> |
| 15 | #include <__iterator/concepts.h> |
| 16 | #include <__ranges/access.h> |
| 17 | #include <__ranges/concepts.h> |
| 18 | #include <__ranges/dangling.h> |
| 19 | #include <__utility/move.h> |
| 20 | |
| 21 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 22 | # pragma GCC system_header |
| 23 | #endif |
| 24 | |
| 25 | _LIBCPP_PUSH_MACROS |
| 26 | #include <__undef_macros> |
| 27 | |
| 28 | #if _LIBCPP_STD_VER >= 20 |
| 29 | |
| 30 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 31 | |
| 32 | namespace ranges { |
| 33 | struct __fill { |
| 34 | template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent> |
| 35 | _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const { |
| 36 | if constexpr (sized_sentinel_for<_Sent, _Iter>) { |
| 37 | auto __n = __last - __first; |
| 38 | return std::__fill_n(std::move(__first), __n, __value); |
| 39 | } else { |
| 40 | return std::__fill(std::move(__first), std::move(__last), __value); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | template <class _Type, output_range<const _Type&> _Range> |
| 45 | _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const { |
| 46 | return (*this)(ranges::begin(__range), ranges::end(__range), __value); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | inline namespace __cpo { |
| 51 | inline constexpr auto fill = __fill{}; |
| 52 | } // namespace __cpo |
| 53 | } // namespace ranges |
| 54 | |
| 55 | _LIBCPP_END_NAMESPACE_STD |
| 56 | |
| 57 | #endif // _LIBCPP_STD_VER >= 20 |
| 58 | |
| 59 | _LIBCPP_POP_MACROS |
| 60 | |
| 61 | #endif // _LIBCPP___ALGORITHM_RANGES_FILL_H |
| 62 | |