[v2] libstdc++: PSTL dispatch for C++20 range random access iterators [PR110512]
Checks
Commit Message
libstdc++: Recognize C++ random access iterators as random access in PSTL
[PR110432]
The check for random access iterators in the PSTL only checks whether the
iterator inherits from the random_access_iterator_tag, failing to recognize
random access iterators originating in C++20 ranges and views.
This patch extends the check to also recognize types that model the C++20
random_access_iterator concept as providing random access.
This is allowed by C++23's P2408, which is safe to backport to C++20,
because
any application that would break already exhibits undefined
behavior due to precondition violation.
libstdc++-v3/ChangeLog:
PR libstdc++/110512
* include/pstl/execution_impl.h Recognize C++20 random access iterators as
random access.
Bootstrapping and testing
* Tested with x86_64-pc-linux-gnu.
---
libstdc++-v3/include/pstl/execution_impl.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
+>;
template <typename... _IteratorTypes>
using __are_random_access_iterators =
__are_iterators_of<std::random_access_iterator_tag, _IteratorTypes...>;
b/libstdc++-v3/include/pstl/execution_impl.h
@@ -22,7 +22,15 @@ namespace __internal
template <typename _IteratorTag, typename... _IteratorTypes>
using __are_iterators_of = std::conjunction<
- std::is_base_of<_IteratorTag, typename
std::iterator_traits<std::decay_t<_IteratorTypes>>::iterator_category>...>;
+#if __cplusplus >= 202002L
+ std::disjunction<
+ std::is_base_of<_IteratorTag, typename
std::iterator_traits<std::decay_t<_IteratorTypes>>::iterator_category>,
+ std::integral_constant<bool,
std::random_access_iterator<_IteratorTypes>>
+ >...
+#else // __cplusplus
+ std::is_base_of<_IteratorTag, typename
std::iterator_traits<std::decay_t<_IteratorTypes>>::iterator_category>...
+#endif // __cplusplus