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 10 commits
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 ::std::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 ::std::tuple<typename ::std::iterator_traits<_Types>::value_type...> value_type;
typedef ::std::tuple<typename ::std::iterator_traits<_Types>::reference...> reference;
typedef ::std::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_(::std::make_tuple(__args...)) {}
explicit zip_forward_iterator(_Types... __args) : __my_it_(__tuple_t<_Types...>{__args...}) {}

reference operator*() const
{
Expand Down
28 changes: 28 additions & 0 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,6 +300,30 @@
#define _ONEDPL_CPP20_SHIFT_LEFT_RIGHT_PRESENT \
(_ONEDPL___cplusplus >= 202002L && (_MSC_VER >= 1921 || _GLIBCXX_RELEASE >= 10))

#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)

#if defined(_MSC_VER) && __INTEL_LLVM_COMPILER < 20240100
Expand Down
12 changes: 12 additions & 0 deletions include/oneapi/dpl/pstl/tuple_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,18 @@ get(const oneapi::dpl::__internal::tuple<_Tp...>&& __a)
{
return ::std::move(__a).template get<_Idx>();
}

// To enable oneapi::dpl::zip_iterator to satisfy the requirements for the std::input_iterator concept in C++20,
// we must provide a basic_common_reference specialization for our internal tuple implementation.
#if _ONEDPL_CPP20_CONCEPTS_PRESENT
akukanov marked this conversation as resolved.
Show resolved Hide resolved
rarutyun marked this conversation as resolved.
Show resolved Hide resolved
template <typename... TTypes, typename... UTypes, template <typename> typename TQual,
template <typename> typename UQual>
struct basic_common_reference<oneapi::dpl::__internal::tuple<TTypes...>, oneapi::dpl::__internal::tuple<UTypes...>,
TQual, UQual>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble understanding TQual and UQual.

Are they just something which is required for this function for it to be of use to the Standard library implementation?
Perhaps it uses these to add type qualifiers like const to the types?

Its not very clear to me as it is written in the standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are required for this function to be used by the standard library implementation. My understanding is that they add cvref-qualifiers to the types.

It is mentioned briefly in the explanation of std::common_reference's required behavior:

"Otherwise, if std::basic_common_reference<std::remove_cvref_t<T1>, std::remove_cvref_t<T2>, T1Q, T2Q>::type exists, where TiQ is a unary alias template such that TiQ is U with the addition of Ti's cv- and reference qualifiers, then the member type type names that type;"

{
using type = oneapi::dpl::__internal::tuple<::std::common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
};
#endif
} // namespace std

#endif // _ONEDPL_TUPLE_IMPL_H
Loading