* [PATCH v2] libstdc++: PSTL dispatch for C++20 range random access iterators [PR110512]
@ 2023-07-03 16:02 Gonzalo Brito Gadeschi
2023-11-11 18:11 ` Gonzalo Brito Gadeschi
0 siblings, 1 reply; 2+ messages in thread
From: Gonzalo Brito Gadeschi @ 2023-07-03 16:02 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]
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(-)
diff --git a/libstdc++-v3/include/pstl/execution_impl.h
b/libstdc++-v3/include/pstl/execution_impl.h
index 64f6cc4357a..c17da29141e 100644
--- a/libstdc++-v3/include/pstl/execution_impl.h
+++ 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
+>;
template <typename... _IteratorTypes>
using __are_random_access_iterators =
__are_iterators_of<std::random_access_iterator_tag, _IteratorTypes...>;
--
2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] libstdc++: PSTL dispatch for C++20 range random access iterators [PR110512]
2023-07-03 16:02 [PATCH v2] libstdc++: PSTL dispatch for C++20 range random access iterators [PR110512] Gonzalo Brito Gadeschi
@ 2023-11-11 18:11 ` Gonzalo Brito Gadeschi
0 siblings, 0 replies; 2+ messages in thread
From: Gonzalo Brito Gadeschi @ 2023-11-11 18:11 UTC (permalink / raw)
To: gcc-patches, libstdc++, pilarlatiesa
[-- Attachment #1: Type: text/plain, Size: 2313 bytes --]
@Pilar, this is the patch. Let me know if you need any help or have
questions. Thank you !
On Mon 3. Jul 2023 at 09:02, Gonzalo Brito Gadeschi <
gonzalo.gadeschi@gmail.com> wrote:
> 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(-)
>
> diff --git a/libstdc++-v3/include/pstl/execution_impl.h
> b/libstdc++-v3/include/pstl/execution_impl.h
> index 64f6cc4357a..c17da29141e 100644
> --- a/libstdc++-v3/include/pstl/execution_impl.h
> +++ 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
> +>;
>
> template <typename... _IteratorTypes>
> using __are_random_access_iterators =
> __are_iterators_of<std::random_access_iterator_tag, _IteratorTypes...>;
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-11 18:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 16:02 [PATCH v2] libstdc++: PSTL dispatch for C++20 range random access iterators [PR110512] Gonzalo Brito Gadeschi
2023-11-11 18:11 ` Gonzalo Brito Gadeschi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).