diff options
author | Michael Levine <mlevine55@bloomberg.net> | 2024-06-07 09:54:38 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-06-08 15:51:40 +0100 |
commit | 0bb1db32ccf54a9de59bea718f7575f7ef22abf5 (patch) | |
tree | 25804a34ef04dffa28b5e3e578f26039e53ad9bc /libstdc++-v3/include/std/numeric | |
parent | 77e84dc4e4e60ec5e7d6d1124e226452aa558108 (diff) | |
download | gcc-0bb1db32ccf54a9de59bea718f7575f7ef22abf5.zip gcc-0bb1db32ccf54a9de59bea718f7575f7ef22abf5.tar.gz gcc-0bb1db32ccf54a9de59bea718f7575f7ef22abf5.tar.bz2 |
libstdc++: Fix std::ranges::iota is not included in numeric [PR108760]
Before this patch, using std::ranges::iota required including
<algorithm> when it should have been sufficient to only include
<numeric>.
libstdc++-v3/ChangeLog:
PR libstdc++/108760
* include/bits/ranges_algo.h (ranges::out_value_result):
Move to <bits/ranges_algobase.h>.
(ranges::iota_result, ranges::__iota_fn, ranges::iota): Move to
<numeric>.
* include/bits/ranges_algobase.h (ranges::out_value_result):
Move to here.
* include/std/numeric (ranges::iota_result, ranges::__iota_fn)
(ranges::iota): Move to here.
* testsuite/25_algorithms/iota/1.cc: Renamed to ...
* testsuite/26_numerics/iota/2.cc: ... here.
Signed-off-by: Michael Levine <mlevine55@bloomberg.net>
Diffstat (limited to 'libstdc++-v3/include/std/numeric')
-rw-r--r-- | libstdc++-v3/include/std/numeric | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric index c912db4..201bb8e 100644 --- a/libstdc++-v3/include/std/numeric +++ b/libstdc++-v3/include/std/numeric @@ -89,6 +89,10 @@ #define __glibcxx_want_saturation_arithmetic #include <bits/version.h> +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 +# include <bits/ranges_algobase.h> // for ranges::out_value_result +#endif + #ifdef __glibcxx_saturation_arithmetic // C++ >= 26 # include <bits/sat_arith.h> #endif @@ -726,6 +730,40 @@ namespace __detail /// @} group numeric_ops #endif // C++17 +namespace ranges +{ +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 + + template<typename _Out, typename _Tp> + using iota_result = out_value_result<_Out, _Tp>; + + struct __iota_fn + { + template<input_or_output_iterator _Out, sentinel_for<_Out> _Sent, weakly_incrementable _Tp> + requires indirectly_writable<_Out, const _Tp&> + constexpr iota_result<_Out, _Tp> + operator()(_Out __first, _Sent __last, _Tp __value) const + { + while (__first != __last) + { + *__first = static_cast<const _Tp&>(__value); + ++__first; + ++__value; + } + return {std::move(__first), std::move(__value)}; + } + + template<weakly_incrementable _Tp, output_range<const _Tp&> _Range> + constexpr iota_result<borrowed_iterator_t<_Range>, _Tp> + operator()(_Range&& __r, _Tp __value) const + { return (*this)(ranges::begin(__r), ranges::end(__r), std::move(__value)); } + }; + + inline constexpr __iota_fn iota{}; + +#endif // __glibcxx_ranges_iota +} // namespace ranges + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std |