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