diff --git a/testing/binary_search_vector.cu b/testing/binary_search_vector.cu index d9a261c45..5e8f8358e 100644 --- a/testing/binary_search_vector.cu +++ b/testing/binary_search_vector.cu @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -16,7 +17,8 @@ template struct vector_like { typedef typename ExampleVector::allocator_type alloc; - typedef typename alloc::template rebind::other new_alloc; + typedef typename thrust::detail::allocator_traits alloc_traits; + typedef typename alloc_traits::template rebind_alloc new_alloc; typedef thrust::detail::vector_base type; }; diff --git a/testing/binary_search_vector_descending.cu b/testing/binary_search_vector_descending.cu index 88ec5a3e3..edc70663a 100644 --- a/testing/binary_search_vector_descending.cu +++ b/testing/binary_search_vector_descending.cu @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -14,7 +15,8 @@ template struct vector_like { typedef typename ExampleVector::allocator_type alloc; - typedef typename alloc::template rebind::other new_alloc; + typedef typename thrust::detail::allocator_traits alloc_traits; + typedef typename alloc_traits::template rebind_alloc new_alloc; typedef thrust::detail::vector_base type; }; diff --git a/testing/functional_placeholders_bitwise.cu b/testing/functional_placeholders_bitwise.cu index bfefb9771..10419535a 100644 --- a/testing/functional_placeholders_bitwise.cu +++ b/testing/functional_placeholders_bitwise.cu @@ -3,16 +3,18 @@ #include #include +#include + static const size_t num_samples = 10000; template struct rebind_vector; -// TODO: C++11: use rebind from allocator_traits template struct rebind_vector, U> { - typedef thrust::host_vector::other> type; + typedef typename thrust::detail::allocator_traits alloc_traits; + typedef typename alloc_traits::template rebind_alloc new_alloc; + typedef thrust::host_vector type; }; template diff --git a/testing/functional_placeholders_logical.cu b/testing/functional_placeholders_logical.cu index 7fcb640fe..b40084b5e 100644 --- a/testing/functional_placeholders_logical.cu +++ b/testing/functional_placeholders_logical.cu @@ -2,16 +2,18 @@ #include #include +#include + static const size_t num_samples = 10000; template struct rebind_vector; -// TODO: C++11: use rebind from allocator_traits template struct rebind_vector, U> { - typedef thrust::host_vector::other> type; + typedef typename thrust::detail::allocator_traits alloc_traits; + typedef typename alloc_traits::template rebind_alloc new_alloc; + typedef thrust::host_vector type; }; template diff --git a/testing/functional_placeholders_relational.cu b/testing/functional_placeholders_relational.cu index 8114ef55e..a610d3419 100644 --- a/testing/functional_placeholders_relational.cu +++ b/testing/functional_placeholders_relational.cu @@ -2,16 +2,18 @@ #include #include +#include + static const size_t num_samples = 10000; template struct rebind_vector; -// TODO: C++11: use rebind from allocator_traits template struct rebind_vector, U> { - typedef thrust::host_vector::other> type; + typedef typename thrust::detail::allocator_traits alloc_traits; + typedef typename alloc_traits::template rebind_alloc new_alloc; + typedef thrust::host_vector type; }; template diff --git a/testing/vector_allocators.cu b/testing/vector_allocators.cu index c7276b28c..568ea7ff6 100644 --- a/testing/vector_allocators.cu +++ b/testing/vector_allocators.cu @@ -7,6 +7,8 @@ template class stateful_allocator : public BaseAlloc { + typedef thrust::detail::allocator_traits base_traits; + public: stateful_allocator(int i) : state(i) { @@ -43,20 +45,35 @@ public: static int last_allocated; static int last_deallocated; - typedef - typename thrust::detail::allocator_traits::pointer - pointer; + typedef typename base_traits::pointer pointer; + typedef typename base_traits::const_pointer const_pointer; + typedef typename base_traits::reference reference; + typedef typename base_traits::const_reference const_reference; pointer allocate(std::size_t size) { + BaseAlloc alloc; last_allocated = state; - return BaseAlloc::allocate(size); + return base_traits::allocate(alloc, size); } void deallocate(pointer ptr, std::size_t size) { + BaseAlloc alloc; last_deallocated = state; - return BaseAlloc::deallocate(ptr, size); + return base_traits::deallocate(alloc, ptr, size); + } + + static void construct(pointer ptr) + { + BaseAlloc alloc; + return base_traits::construct(alloc, ptr); + } + + static void destroy(pointer ptr) + { + BaseAlloc alloc; + return base_traits::destroy(alloc, ptr); } bool operator==(const stateful_allocator &rhs) const diff --git a/thrust/detail/allocator/allocator_traits.h b/thrust/detail/allocator/allocator_traits.h index 768f74dab..c2557b57e 100644 --- a/thrust/detail/allocator/allocator_traits.h +++ b/thrust/detail/allocator/allocator_traits.h @@ -347,6 +347,10 @@ template }; #endif + // Deprecated std::allocator typedefs that we need: + typedef typename thrust::detail::pointer_traits::reference reference; + typedef typename thrust::detail::pointer_traits::reference const_reference; + inline __host__ __device__ static pointer allocate(allocator_type &a, size_type n); diff --git a/thrust/detail/allocator/allocator_traits.inl b/thrust/detail/allocator/allocator_traits.inl index c163502e8..0818941f6 100644 --- a/thrust/detail/allocator/allocator_traits.inl +++ b/thrust/detail/allocator/allocator_traits.inl @@ -70,6 +70,12 @@ public: is_empty >::type; + // std::allocator_traits doesn't provide these, but + // thrust::detail::allocator_traits does. These used to be part of the + // std::allocator API but were deprecated in C++17. + using reference = typename thrust::detail::pointer_traits::reference; + using const_reference = typename thrust::detail::pointer_traits::reference; + template using rebind_alloc = std::allocator; template diff --git a/thrust/detail/contiguous_storage.h b/thrust/detail/contiguous_storage.h index 84485e754..a128223a9 100644 --- a/thrust/detail/contiguous_storage.h +++ b/thrust/detail/contiguous_storage.h @@ -43,14 +43,8 @@ template typedef typename alloc_traits::const_pointer const_pointer; typedef typename alloc_traits::size_type size_type; typedef typename alloc_traits::difference_type difference_type; - - // XXX we should bring reference & const_reference into allocator_traits - // at the moment, it's unclear how -- we have nothing analogous to - // rebind_pointer for references - // we either need to add reference_traits or extend the existing - // pointer_traits to support wrapped references - typedef typename Alloc::reference reference; - typedef typename Alloc::const_reference const_reference; + typedef typename alloc_traits::reference reference; + typedef typename alloc_traits::const_reference const_reference; typedef thrust::detail::normal_iterator iterator; typedef thrust::detail::normal_iterator const_iterator;