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

Deprecate and replace some Thrust iterator traits #3928

Merged
merged 2 commits into from
Feb 26, 2025
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
10 changes: 6 additions & 4 deletions thrust/examples/cuda/range_view.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <thrust/for_each.h>
#include <thrust/iterator/counting_iterator.h>

#include <cuda/std/iterator>

#include <iostream>

#include "../include/host_device.h"
Expand All @@ -20,10 +22,10 @@ class range_view
{
public:
using iterator = Iterator;
using value_type = typename thrust::iterator_traits<iterator>::value_type;
using pointer = typename thrust::iterator_traits<iterator>::pointer;
using difference_type = typename thrust::iterator_traits<iterator>::difference_type;
using reference = typename thrust::iterator_traits<iterator>::reference;
using value_type = typename cuda::std::iterator_traits<iterator>::value_type;
using pointer = typename cuda::std::iterator_traits<iterator>::pointer;
using difference_type = typename cuda::std::iterator_traits<iterator>::difference_type;
using reference = typename cuda::std::iterator_traits<iterator>::reference;

private:
const iterator first;
Expand Down
2 changes: 1 addition & 1 deletion thrust/examples/expand.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator expand(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator output)
{
using difference_type = typename thrust::iterator_difference<InputIterator1>::type;
using difference_type = typename cuda::std::iterator_traits<InputIterator1>::difference_type;

difference_type input_size = thrust::distance(first1, last1);
difference_type output_size = thrust::reduce(first1, last1);
Expand Down
2 changes: 1 addition & 1 deletion thrust/examples/repeated_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template <typename Iterator>
class repeated_range
{
public:
using difference_type = typename thrust::iterator_difference<Iterator>::type;
using difference_type = typename cuda::std::iterator_traits<Iterator>::difference_type;

struct repeat_functor
{
Expand Down
2 changes: 1 addition & 1 deletion thrust/examples/strided_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template <typename Iterator>
class strided_range
{
public:
using difference_type = typename thrust::iterator_difference<Iterator>::type;
using difference_type = typename cuda::std::iterator_traits<Iterator>::difference_type;

struct stride_functor
{
Expand Down
2 changes: 1 addition & 1 deletion thrust/examples/tiled_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template <typename Iterator>
class tiled_range
{
public:
using difference_type = typename thrust::iterator_difference<Iterator>::type;
using difference_type = typename cuda::std::iterator_traits<Iterator>::difference_type;

struct tile_functor
{
Expand Down
2 changes: 1 addition & 1 deletion thrust/testing/counting_iterator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ DECLARE_UNITTEST(TestCountingIteratorLowerBound);
void TestCountingIteratorDifference()
{
using Iterator = thrust::counting_iterator<std::uint64_t>;
using Difference = thrust::iterator_difference<Iterator>::type;
using Difference = thrust::detail::it_difference_t<Iterator>;

Difference diff = std::numeric_limits<std::uint32_t>::max() + 1;

Expand Down
4 changes: 2 additions & 2 deletions thrust/testing/cuda/adjacent_difference.cu
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ DECLARE_UNITTEST(TestAdjacentDifferenceCudaStreams);
struct detect_wrong_difference
{
using difference_type = void;
using value_type = void;
using value_type = long long;
using pointer = void;
using reference = void;
using reference = detect_wrong_difference;
using iterator_category = ::cuda::std::output_iterator_tag;

bool* flag;
Expand Down
2 changes: 1 addition & 1 deletion thrust/testing/omp/reduce_intervals.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
template <typename InputIterator, typename OutputIterator, typename BinaryFunction, typename Decomposition>
void reduce_intervals(InputIterator input, OutputIterator output, BinaryFunction binary_op, Decomposition decomp)
{
using OutputType = typename thrust::iterator_value<OutputIterator>::type;
using OutputType = thrust::detail::it_value_t<OutputIterator>;
using index_type = typename Decomposition::index_type;

// wrap binary_op
Expand Down
2 changes: 1 addition & 1 deletion thrust/testing/sort_permutation_iterator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ template <typename Iterator>
class strided_range
{
public:
using difference_type = typename thrust::iterator_difference<Iterator>::type;
using difference_type = thrust::detail::it_difference_t<Iterator>;

struct stride_functor
{
Expand Down
2 changes: 1 addition & 1 deletion thrust/testing/trivial_sequence.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void test(Iterator first, Iterator last)
using System = typename thrust::iterator_system<Iterator>::type;
System system;
thrust::detail::trivial_sequence<Iterator, System> ts(system, first, last);
using ValueType = typename thrust::iterator_traits<Iterator>::value_type;
using ValueType = typename ::cuda::std::iterator_traits<Iterator>::value_type;

ASSERT_EQUAL_QUIET((ValueType) ts.begin()[0], ValueType(0, 11));
ASSERT_EQUAL_QUIET((ValueType) ts.begin()[1], ValueType(2, 11));
Expand Down
5 changes: 3 additions & 2 deletions thrust/testing/unique.cu
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void TestUniqueCopyDispatchImplicit()
DECLARE_UNITTEST(TestUniqueCopyDispatchImplicit);

template <typename ForwardIterator>
typename thrust::iterator_traits<ForwardIterator>::difference_type
typename ::cuda::std::iterator_traits<ForwardIterator>::difference_type
unique_count(my_system& system, ForwardIterator, ForwardIterator)
{
system.validate_dispatch();
Expand All @@ -98,7 +98,8 @@ void TestUniqueCountDispatchExplicit()
DECLARE_UNITTEST(TestUniqueCountDispatchExplicit);

template <typename ForwardIterator>
typename thrust::iterator_traits<ForwardIterator>::difference_type unique_count(my_tag, ForwardIterator, ForwardIterator)
typename ::cuda::std::iterator_traits<ForwardIterator>::difference_type
unique_count(my_tag, ForwardIterator, ForwardIterator)
{
return 13;
}
Expand Down
8 changes: 4 additions & 4 deletions thrust/testing/unittest/assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ void assert_equal(
const std::string& filename = "unknown",
int lineno = -1)
{
using difference_type = typename THRUST_NS_QUALIFIER::iterator_difference<ForwardIterator1>::type;
using InputType = typename THRUST_NS_QUALIFIER::iterator_value<ForwardIterator1>::type;
using difference_type = THRUST_NS_QUALIFIER::detail::it_difference_t<ForwardIterator1>;
using InputType = THRUST_NS_QUALIFIER::detail::it_value_t<ForwardIterator1>;

bool failure = false;

Expand Down Expand Up @@ -486,7 +486,7 @@ void assert_equal(
const std::string& filename = "unknown",
int lineno = -1)
{
using InputType = typename THRUST_NS_QUALIFIER::iterator_traits<ForwardIterator1>::value_type;
using InputType = typename ::cuda::std::iterator_traits<ForwardIterator1>::value_type;
assert_equal(first1, last1, first2, last2, THRUST_NS_QUALIFIER::equal_to<InputType>(), filename, lineno);
}

Expand All @@ -501,7 +501,7 @@ void assert_almost_equal(
const double a_tol = DEFAULT_ABSOLUTE_TOL,
const double r_tol = DEFAULT_RELATIVE_TOL)
{
using InputType = typename THRUST_NS_QUALIFIER::iterator_traits<ForwardIterator1>::value_type;
using InputType = typename ::cuda::std::iterator_traits<ForwardIterator1>::value_type;
assert_equal(first1, last1, first2, last2, almost_equal_to<InputType>(a_tol, r_tol), filename, lineno);
}

Expand Down
4 changes: 2 additions & 2 deletions thrust/testing/zip_iterator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct TestZipIteratorReference
using IteratorTuple1 = tuple<Iterator1, Iterator2>;
using ZipIterator1 = zip_iterator<IteratorTuple1>;

using zip_iterator_reference_type1 = typename iterator_reference<ZipIterator1>::type;
using zip_iterator_reference_type1 = thrust::detail::it_reference_t<ZipIterator1>;

host_vector<T> h_variable(1);

Expand All @@ -128,7 +128,7 @@ struct TestZipIteratorReference
using IteratorTuple2 = tuple<Iterator3, Iterator4>;
using ZipIterator2 = zip_iterator<IteratorTuple2>;

using zip_iterator_reference_type2 = typename iterator_reference<ZipIterator2>::type;
using zip_iterator_reference_type2 = thrust::detail::it_reference_t<ZipIterator2>;

device_vector<T> d_variable(1);

Expand Down
4 changes: 2 additions & 2 deletions thrust/thrust/advance.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ template <typename InputIterator, typename Distance>
_CCCL_HOST_DEVICE
InputIterator next(
InputIterator i
, typename iterator_traits<InputIterator>::difference_type n = 1
, typename ::cuda::std::iterator_traits<InputIterator>::difference_type n = 1
);
#endif

Expand Down Expand Up @@ -135,7 +135,7 @@ template <typename BidirectionalIterator, typename Distance>
_CCCL_HOST_DEVICE
BidirectionalIterator prev(
BidirectionalIterator i
, typename iterator_traits<BidirectionalIterator>::difference_type n = 1
, typename ::cuda::std::iterator_traits<BidirectionalIterator>::difference_type n = 1
);
#endif

Expand Down
9 changes: 4 additions & 5 deletions thrust/thrust/count.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ THRUST_NAMESPACE_BEGIN
* \see https://en.cppreference.com/w/cpp/algorithm/count
*/
template <typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Expand Down Expand Up @@ -131,7 +131,7 @@ count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
* \see https://en.cppreference.com/w/cpp/algorithm/count
*/
template <typename InputIterator, typename EqualityComparable>
typename thrust::iterator_traits<InputIterator>::difference_type
thrust::detail::it_difference_t<InputIterator>
count(InputIterator first, InputIterator last, const EqualityComparable& value);

/*! \p count_if finds the number of elements in <tt>[first,last)</tt> for which
Expand Down Expand Up @@ -184,7 +184,7 @@ count(InputIterator first, InputIterator last, const EqualityComparable& value);
* \see https://en.cppreference.com/w/cpp/algorithm/count
*/
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Expand Down Expand Up @@ -234,8 +234,7 @@ count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
* \see https://en.cppreference.com/w/cpp/algorithm/count
*/
template <typename InputIterator, typename Predicate>
typename thrust::iterator_traits<InputIterator>::difference_type
count_if(InputIterator first, InputIterator last, Predicate pred);
thrust::detail::it_difference_t<InputIterator> count_if(InputIterator first, InputIterator last, Predicate pred);

/*! \} // end counting
* \} // end reductions
Expand Down
7 changes: 4 additions & 3 deletions thrust/thrust/detail/advance.inl
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,24 @@ _CCCL_HOST_DEVICE void advance(InputIterator& i, Distance n)
}

template <typename InputIterator>
_CCCL_HOST_DEVICE InputIterator next(InputIterator i, typename iterator_traits<InputIterator>::difference_type n = 1)
_CCCL_HOST_DEVICE InputIterator next(InputIterator i, thrust::detail::it_difference_t<InputIterator> n = 1)
{
thrust::system::detail::generic::advance(i, n);
return i;
}

template <typename BidirectionalIterator>
_CCCL_HOST_DEVICE BidirectionalIterator
prev(BidirectionalIterator i, typename iterator_traits<BidirectionalIterator>::difference_type n = 1)
prev(BidirectionalIterator i, thrust::detail::it_difference_t<BidirectionalIterator> n = 1)
{
thrust::system::detail::generic::advance(i, -n);
return i;
}

// FIXME(bgruber): what does this prevent against?
template <typename BidirectionalIterator>
_CCCL_HOST_DEVICE
typename detail::disable_if<has_difference_type<iterator_traits<BidirectionalIterator>>::value,
typename detail::disable_if<has_difference_type<::cuda::std::iterator_traits<BidirectionalIterator>>::value,
BidirectionalIterator>::type
prev(BidirectionalIterator i, typename detail::pointer_traits<BidirectionalIterator>::difference_type n = 1)
{
Expand Down
10 changes: 5 additions & 5 deletions thrust/thrust/detail/allocator/copy_construct_range.inl
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ _CCCL_HOST_DEVICE enable_if_convertible_t<FromSystem, ToSystem, Pointer> uniniti
ZipIterator end = begin;

// get a zip_iterator pointing to the end
const typename thrust::iterator_difference<InputIterator>::type n = thrust::distance(first, last);
const thrust::detail::it_difference_t<InputIterator> n = thrust::distance(first, last);
thrust::advance(end, n);

// create a functor
using InputType = typename iterator_traits<InputIterator>::value_type;
using OutputType = typename iterator_traits<Pointer>::value_type;
using InputType = it_value_t<InputIterator>;
using OutputType = it_value_t<Pointer>;

// do the for_each
// note we use to_system to dispatch the for_each
Expand Down Expand Up @@ -135,8 +135,8 @@ _CCCL_HOST_DEVICE enable_if_convertible_t<FromSystem, ToSystem, Pointer> uniniti
ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first, result));

// create a functor
using InputType = typename iterator_traits<InputIterator>::value_type;
using OutputType = typename iterator_traits<Pointer>::value_type;
using InputType = it_value_t<InputIterator>;
using OutputType = it_value_t<Pointer>;

// do the for_each_n
// note we use to_system to dispatch the for_each_n
Expand Down
4 changes: 2 additions & 2 deletions thrust/thrust/detail/allocator/tagged_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class tagged_allocator
using value_type = T;
using pointer = typename thrust::detail::pointer_traits<Pointer>::template rebind<T>::other;
using const_pointer = typename thrust::detail::pointer_traits<Pointer>::template rebind<const T>::other;
using reference = typename thrust::iterator_reference<pointer>::type;
using const_reference = typename thrust::iterator_reference<const_pointer>::type;
using reference = thrust::detail::it_reference_t<pointer>;
using const_reference = thrust::detail::it_reference_t<const_pointer>;
using size_type = std::size_t;
using difference_type = typename thrust::detail::pointer_traits<pointer>::difference_type;
using system_type = Tag;
Expand Down
9 changes: 4 additions & 5 deletions thrust/thrust/detail/count.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,25 @@
THRUST_NAMESPACE_BEGIN

template <typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
const EqualityComparable& value);

template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Predicate pred);

template <typename InputIterator, typename EqualityComparable>
typename thrust::iterator_traits<InputIterator>::difference_type
thrust::detail::it_difference_t<InputIterator>
count(InputIterator first, InputIterator last, const EqualityComparable& value);

template <typename InputIterator, typename Predicate>
typename thrust::iterator_traits<InputIterator>::difference_type
count_if(InputIterator first, InputIterator last, Predicate pred);
thrust::detail::it_difference_t<InputIterator> count_if(InputIterator first, InputIterator last, Predicate pred);

THRUST_NAMESPACE_END

Expand Down
9 changes: 4 additions & 5 deletions thrust/thrust/detail/count.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ THRUST_NAMESPACE_BEGIN

_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Expand All @@ -47,7 +47,7 @@ count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,

_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Expand All @@ -58,7 +58,7 @@ count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
} // end count_if()

template <typename InputIterator, typename EqualityComparable>
typename thrust::iterator_traits<InputIterator>::difference_type
thrust::detail::it_difference_t<InputIterator>
count(InputIterator first, InputIterator last, const EqualityComparable& value)
{
using thrust::system::detail::generic::select_system;
Expand All @@ -71,8 +71,7 @@ count(InputIterator first, InputIterator last, const EqualityComparable& value)
} // end count()

template <typename InputIterator, typename Predicate>
typename thrust::iterator_traits<InputIterator>::difference_type
count_if(InputIterator first, InputIterator last, Predicate pred)
thrust::detail::it_difference_t<InputIterator> count_if(InputIterator first, InputIterator last, Predicate pred)
{
using thrust::system::detail::generic::select_system;

Expand Down
3 changes: 1 addition & 2 deletions thrust/thrust/detail/distance.inl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ THRUST_NAMESPACE_BEGIN

_CCCL_EXEC_CHECK_DISABLE
template <typename InputIterator>
inline _CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
distance(InputIterator first, InputIterator last)
inline _CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator> distance(InputIterator first, InputIterator last)
{
return thrust::system::detail::generic::distance(first, last);
} // end distance()
Expand Down
3 changes: 1 addition & 2 deletions thrust/thrust/detail/get_iterator_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ namespace detail
// --------------------------------------------------
// it is okay to dereference iterator in the usual way
template <typename DerivedPolicy, typename Iterator>
_CCCL_HOST_DEVICE typename thrust::iterator_traits<Iterator>::value_type
get_iterator_value(thrust::execution_policy<DerivedPolicy>&, Iterator it)
_CCCL_HOST_DEVICE it_value_t<Iterator> get_iterator_value(thrust::execution_policy<DerivedPolicy>&, Iterator it)
{
return *it;
} // get_iterator_value(exec,Iterator);
Expand Down
Loading
Loading