Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable zip_iterator to satisfy C++20 std::input_iterator constraint #1408

Merged
merged 16 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions include/oneapi/dpl/pstl/iterator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,26 @@ struct __make_references
template <typename... _Types>
class zip_forward_iterator
{
template <typename... _Ts>
using __tuple_t =
#if _ONEDPL_CAN_USE_STD_TUPLE_PROXY_ITERATOR
::std::tuple<_Ts...>;
#else
oneapi::dpl::__internal::tuple<_Ts...>;
#endif

static const ::std::size_t __num_types = sizeof...(_Types);
typedef typename oneapi::dpl::__internal::tuple<_Types...> __it_types;
typedef __tuple_t<_Types...> __it_types;
danhoeflinger marked this conversation as resolved.
Show resolved Hide resolved

public:
typedef ::std::make_signed_t<::std::size_t> difference_type;
typedef oneapi::dpl::__internal::tuple<typename ::std::iterator_traits<_Types>::value_type...> value_type;
typedef oneapi::dpl::__internal::tuple<typename ::std::iterator_traits<_Types>::reference...> reference;
typedef oneapi::dpl::__internal::tuple<typename ::std::iterator_traits<_Types>::pointer...> pointer;
typedef __tuple_t<typename ::std::iterator_traits<_Types>::value_type...> value_type;
typedef __tuple_t<typename ::std::iterator_traits<_Types>::reference...> reference;
typedef __tuple_t<typename ::std::iterator_traits<_Types>::pointer...> pointer;
typedef ::std::forward_iterator_tag iterator_category;

zip_forward_iterator() : __my_it_() {}
explicit zip_forward_iterator(_Types... __args) : __my_it_(oneapi::dpl::__internal::make_tuple(__args...)) {}
explicit zip_forward_iterator(_Types... __args) : __my_it_(__tuple_t<_Types...>{__args...}) {}

reference operator*() const
{
Expand Down
29 changes: 27 additions & 2 deletions include/oneapi/dpl/pstl/onedpl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#ifndef _ONEDPL_CONFIG_H
#define _ONEDPL_CONFIG_H

#if _ONEDPL___cplusplus >= 202002L && __has_include(<version>)
# include <version>
#endif

akukanov marked this conversation as resolved.
Show resolved Hide resolved
#ifndef _PSTL_VERSION
# define _PSTL_VERSION 11000
# define _PSTL_VERSION_MAJOR (_PSTL_VERSION / 1000)
Expand Down Expand Up @@ -296,8 +300,29 @@
#define _ONEDPL_CPP20_SHIFT_LEFT_RIGHT_PRESENT \
(_ONEDPL___cplusplus >= 202002L && (_MSC_VER >= 1921 || _GLIBCXX_RELEASE >= 10))

#define _ONEDPL_CPP20_CONCEPTS_PRESENT \
(_ONEDPL___cplusplus >= 202002L && (_MSC_VER >= 1923 || _GLIBCXX_RELEASE >= 10 || _LIBCPP_VERSION >= 13000))
#if _ONEDPL___cplusplus >= 202002L && __cpp_concepts >= 201907L && __cpp_lib_concepts >= 202002L
# define _ONEDPL_CPP20_CONCEPTS_PRESENT 1
#else
# define _ONEDPL_CPP20_CONCEPTS_PRESENT 0
#endif

#if _ONEDPL___cplusplus >= 202302L && __cpp_lib_tuple_like >= 202207L
# define _ONEDPL_CPP23_TUPLE_LIKE_COMMON_REFERENCE_PRESENT 1
#else
# define _ONEDPL_CPP23_TUPLE_LIKE_COMMON_REFERENCE_PRESENT 0
#endif

#if _ONEDPL___cplusplus >= 202302L && __cpp_lib_ranges_zip >= 202110L
# define _ONEDPL_CPP23_RANGES_ZIP_PRESENT 1
#else
# define _ONEDPL_CPP23_RANGES_ZIP_PRESENT 0
#endif
akukanov marked this conversation as resolved.
Show resolved Hide resolved

// To use std::tuple as a proxy reference and satisfy iterator concepts for C++20 and beyond, we need
// the changes to std::tuple in P2321R2 and the tuple-like basic_common_reference specialization in P2165R4.
danhoeflinger marked this conversation as resolved.
Show resolved Hide resolved
#define _ONEDPL_CAN_USE_STD_TUPLE_PROXY_ITERATOR \
(!_ONEDPL_CPP20_CONCEPTS_PRESENT || \
(_ONEDPL_CPP23_RANGES_ZIP_PRESENT && _ONEDPL_CPP23_TUPLE_LIKE_COMMON_REFERENCE_PRESENT))

#define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name)

Expand Down
Loading