From: Michael Levine Date: Fri, 7 Jun 2024 08:54:38 +0000 (+0100) Subject: libstdc++: Fix std::ranges::iota is not included in numeric [PR108760] X-Git-Tag: releases/gcc-14.3.0~173 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=399ca300412970bcc11104d431d32770d0fc6c65;p=thirdparty%2Fgcc.git libstdc++: Fix std::ranges::iota is not included in numeric [PR108760] Before this patch, using std::ranges::iota required including when it should have been sufficient to only include . For the backport to the release branch ranges::iota is defined in so that it's available in both and . This avoids breaking code that compiles successfully using existing releases where defines ranges::iota. libstdc++-v3/ChangeLog: PR libstdc++/108760 * include/bits/ranges_algo.h (ranges::out_value_result) (ranges::iota_result, ranges::__iota_fn, ranges::iota): Move to . * include/bits/ranges_algobase.h (ranges::out_value_result): (ranges::iota_result, ranges::__iota_fn, ranges::iota): Move to here. * include/std/numeric: Include . * testsuite/25_algorithms/iota/1.cc: Renamed to ... * testsuite/26_numerics/iota/2.cc: ... here. Signed-off-by: Michael Levine (cherry picked from commit 0bb1db32ccf54a9de59bea718f7575f7ef22abf5) --- diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 6bac65bc564d..59374e3dbd0c 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -3535,58 +3535,6 @@ namespace ranges #endif // __glibcxx_ranges_contains -#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 - - template - struct out_value_result - { - [[no_unique_address]] _Out out; - [[no_unique_address]] _Tp value; - - template - requires convertible_to - && convertible_to - constexpr - operator out_value_result<_Out2, _Tp2>() const & - { return {out, value}; } - - template - requires convertible_to<_Out, _Out2> - && convertible_to<_Tp, _Tp2> - constexpr - operator out_value_result<_Out2, _Tp2>() && - { return {std::move(out), std::move(value)}; } - }; - - template - using iota_result = out_value_result<_Out, _Tp>; - - struct __iota_fn - { - template _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(__value); - ++__first; - ++__value; - } - return {std::move(__first), std::move(__value)}; - } - - template _Range> - constexpr iota_result, _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 - #if __glibcxx_ranges_find_last >= 202207L // C++ >= 23 struct __find_last_fn diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h index a013de40318e..40f5bb707e00 100644 --- a/libstdc++-v3/include/bits/ranges_algobase.h +++ b/libstdc++-v3/include/bits/ranges_algobase.h @@ -71,6 +71,56 @@ namespace ranges __is_move_iterator> = true; } // namespace __detail +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 + template + struct out_value_result + { + [[no_unique_address]] _Out out; + [[no_unique_address]] _Tp value; + + template + requires convertible_to + && convertible_to + constexpr + operator out_value_result<_Out2, _Tp2>() const & + { return {out, value}; } + + template + requires convertible_to<_Out, _Out2> + && convertible_to<_Tp, _Tp2> + constexpr + operator out_value_result<_Out2, _Tp2>() && + { return {std::move(out), std::move(value)}; } + }; + + template + using iota_result = out_value_result<_Out, _Tp>; + + struct __iota_fn + { + template _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(__value); + ++__first; + ++__value; + } + return {std::move(__first), std::move(__value)}; + } + + template _Range> + constexpr iota_result, _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 + struct __equal_fn { template _Sent1, diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric index a4cda3d5c36f..ab6ae22609ba 100644 --- a/libstdc++-v3/include/std/numeric +++ b/libstdc++-v3/include/std/numeric @@ -89,6 +89,10 @@ #define __glibcxx_want_saturation_arithmetic #include +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 +# include // for ranges::out_value_result, ranges::iota +#endif + #ifdef __glibcxx_saturation_arithmetic // C++ >= 26 # include #endif diff --git a/libstdc++-v3/testsuite/25_algorithms/iota/1.cc b/libstdc++-v3/testsuite/26_numerics/iota/2.cc similarity index 96% rename from libstdc++-v3/testsuite/25_algorithms/iota/1.cc rename to libstdc++-v3/testsuite/26_numerics/iota/2.cc index ebadeee79a13..b14580b8be19 100644 --- a/libstdc++-v3/testsuite/25_algorithms/iota/1.cc +++ b/libstdc++-v3/testsuite/26_numerics/iota/2.cc @@ -1,6 +1,5 @@ // { dg-do run { target c++23 } } -#include #include #include #include