| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H |
| 11 | #define _LIBCPP___NUMERIC_RANGES_IOTA_H |
| 12 | |
| 13 | #include <__algorithm/out_value_result.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/as_const.h> |
| 20 | #include <__utility/move.h> |
| 21 | |
| 22 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 23 | # pragma GCC system_header |
| 24 | #endif |
| 25 | |
| 26 | _LIBCPP_PUSH_MACROS |
| 27 | #include <__undef_macros> |
| 28 | |
| 29 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 30 | |
| 31 | #if _LIBCPP_STD_VER >= 23 |
| 32 | namespace ranges { |
| 33 | template <typename _Out, typename _Tp> |
| 34 | using iota_result = ranges::out_value_result<_Out, _Tp>; |
| 35 | |
| 36 | struct __iota_fn { |
| 37 | public: |
| 38 | template <input_or_output_iterator _Out, sentinel_for<_Out> _Sent, weakly_incrementable _Tp> |
| 39 | requires indirectly_writable<_Out, const _Tp&> |
| 40 | _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp __value) { |
| 41 | while (__first != __last) { |
| 42 | *__first = std::as_const(__value); |
| 43 | ++__first; |
| 44 | ++__value; |
| 45 | } |
| 46 | return {std::move(__first), std::move(__value)}; |
| 47 | } |
| 48 | |
| 49 | template <weakly_incrementable _Tp, ranges::output_range<const _Tp&> _Range> |
| 50 | _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<ranges::borrowed_iterator_t<_Range>, _Tp> |
| 51 | operator()(_Range&& __r, _Tp __value) { |
| 52 | return operator()(ranges::begin(__r), ranges::end(__r), std::move(__value)); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | inline constexpr auto iota = __iota_fn{}; |
| 57 | } // namespace ranges |
| 58 | |
| 59 | #endif // _LIBCPP_STD_VER >= 23 |
| 60 | |
| 61 | _LIBCPP_END_NAMESPACE_STD |
| 62 | |
| 63 | _LIBCPP_POP_MACROS |
| 64 | |
| 65 | #endif // _LIBCPP___NUMERIC_RANGES_IOTA_H |
| 66 | |