| Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 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/ranges_fill_n.h> |
| 13 | #include <__config> |
| 14 | #include <__iterator/concepts.h> |
| 15 | #include <__ranges/access.h> |
| 16 | #include <__ranges/concepts.h> |
| 17 | #include <__ranges/dangling.h> |
| 18 | |
| 19 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 20 | # pragma GCC system_header |
| 21 | #endif |
| 22 | |
| Kaido Kert | 56d7c4e | 2024-04-13 12:59:27 -0700 | [diff] [blame^] | 23 | #if _LIBCPP_STD_VER >= 20 |
| Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 24 | |
| 25 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 26 | |
| 27 | namespace ranges { |
| 28 | namespace __fill { |
| 29 | struct __fn { |
| 30 | template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent> |
| 31 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 32 | _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const { |
| 33 | if constexpr(random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) { |
| 34 | return ranges::fill_n(__first, __last - __first, __value); |
| 35 | } else { |
| 36 | for (; __first != __last; ++__first) |
| 37 | *__first = __value; |
| 38 | return __first; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | template <class _Type, output_range<const _Type&> _Range> |
| 43 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 44 | borrowed_iterator_t<_Range> operator()(_Range&& __range, const _Type& __value) const { |
| 45 | return (*this)(ranges::begin(__range), ranges::end(__range), __value); |
| 46 | } |
| 47 | }; |
| 48 | } // namespace __fill |
| 49 | |
| 50 | inline namespace __cpo { |
| 51 | inline constexpr auto fill = __fill::__fn{}; |
| 52 | } // namespace __cpo |
| 53 | } // namespace ranges |
| 54 | |
| 55 | _LIBCPP_END_NAMESPACE_STD |
| 56 | |
| Kaido Kert | 56d7c4e | 2024-04-13 12:59:27 -0700 | [diff] [blame^] | 57 | #endif // _LIBCPP_STD_VER >= 20 |
| Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 58 | |
| 59 | #endif // _LIBCPP___ALGORITHM_RANGES_FILL_H |