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

Rename and refactor transform_iterator_base #1987

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions thrust/thrust/iterator/detail/transform_iterator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
#include <thrust/detail/type_traits/result_of_adaptable_function.h>
#include <thrust/iterator/iterator_adaptor.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/type_traits/remove_cvref.h>

THRUST_NAMESPACE_BEGIN
Expand All @@ -40,27 +38,29 @@ class transform_iterator;
namespace detail
{

// Compute the iterator_adaptor instantiation to be used for transform_iterator
// Type function to compute the iterator_adaptor instantiation to be used for transform_iterator
template <class UnaryFunc, class Iterator, class Reference, class Value>
struct transform_iterator_base
struct make_transform_iterator_base
{
private:
// By default, dereferencing the iterator yields the same as the function.
using reference = typename thrust::detail::ia_dflt_help<
Reference,
thrust::detail::result_of_adaptable_function<UnaryFunc(typename thrust::iterator_value<Iterator>::type)>>::type;
// FIXME(bgruber): the next line should be correct, but thrust::identity<T> lies and advertises a ::return_type of T,
// while its operator() returns const T& (which __invoke_of correctly detects), which causes transform_iterator to
// crash during dereferencing.
// using wrapped_func_ret_t = ::cuda::std::__invoke_of<UnaryFunc, iterator_value_t<Iterator>>;
using wrapped_func_ret_t = result_of_adaptable_function<UnaryFunc(iterator_value_t<Iterator>)>;

// To get the default for Value: remove cvref on the result type.
using value_type = typename thrust::detail::ia_dflt_help<Value, thrust::remove_cvref<reference>>::type;
// By default, dereferencing the iterator yields the same as the function.
using reference = typename ia_dflt_help<Reference, wrapped_func_ret_t>::type;
using value_type = typename ia_dflt_help<Value, remove_cvref<reference>>::type;

public:
using type =
thrust::iterator_adaptor<transform_iterator<UnaryFunc, Iterator, Reference, Value>,
Iterator,
value_type,
thrust::use_default,
typename thrust::iterator_traits<Iterator>::iterator_category,
reference>;
iterator_adaptor<transform_iterator<UnaryFunc, Iterator, Reference, Value>,
Iterator,
value_type,
use_default,
typename iterator_traits<Iterator>::iterator_category,
reference>;
};

} // namespace detail
Expand Down
5 changes: 3 additions & 2 deletions thrust/thrust/iterator/transform_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ THRUST_NAMESPACE_BEGIN
*/
template <class AdaptableUnaryFunction, class Iterator, class Reference = use_default, class Value = use_default>
class transform_iterator
: public detail::transform_iterator_base<AdaptableUnaryFunction, Iterator, Reference, Value>::type
: public detail::make_transform_iterator_base<AdaptableUnaryFunction, Iterator, Reference, Value>::type
{
/*! \cond
*/

public:
using super_t = typename detail::transform_iterator_base<AdaptableUnaryFunction, Iterator, Reference, Value>::type;
using super_t =
typename detail::make_transform_iterator_base<AdaptableUnaryFunction, Iterator, Reference, Value>::type;

friend class thrust::iterator_core_access;
/*! \endcond
Expand Down
Loading