|
23 | 23 | #include <thrust/detail/type_deduction.h>
|
24 | 24 | #endif
|
25 | 25 |
|
| 26 | +#include <memory> |
26 | 27 | #include <new>
|
27 | 28 |
|
28 | 29 | namespace thrust
|
29 | 30 | {
|
30 | 31 | namespace detail
|
31 | 32 | {
|
| 33 | + |
| 34 | +#if THRUST_CPP_DIALECT >= 2011 |
| 35 | + |
| 36 | +// std::allocator's member functions are deprecated in C++17 and removed in |
| 37 | +// C++20, so we can't just use the generic implementation for allocator_traits |
| 38 | +// that calls the allocator's member functions. |
| 39 | +// Instead, specialize allocator_traits for std::allocator and defer to |
| 40 | +// std::allocator_traits<std::allocator> and let the STL do whatever it needs |
| 41 | +// to for the current c++ version. Manually forward the calls to suppress |
| 42 | +// host/device warnings. |
| 43 | +template <typename T> |
| 44 | +struct allocator_traits<std::allocator<T>> |
| 45 | + : public std::allocator_traits<std::allocator<T>> |
| 46 | +{ |
| 47 | +private: |
| 48 | + using superclass = std::allocator_traits<std::allocator<T>>; |
| 49 | + |
| 50 | +public: |
| 51 | + using allocator_type = typename superclass::allocator_type; |
| 52 | + using value_type = typename superclass::value_type; |
| 53 | + using pointer = typename superclass::pointer; |
| 54 | + using const_pointer = typename superclass::const_pointer; |
| 55 | + using void_pointer = typename superclass::void_pointer; |
| 56 | + using const_void_pointer = typename superclass::const_void_pointer; |
| 57 | + using difference_type = typename superclass::difference_type; |
| 58 | + using size_type = typename superclass::size_type; |
| 59 | + using propagate_on_container_swap = typename superclass::propagate_on_container_swap; |
| 60 | + using propagate_on_container_copy_assignment = |
| 61 | + typename superclass::propagate_on_container_copy_assignment; |
| 62 | + using propagate_on_container_move_assignment = |
| 63 | + typename superclass::propagate_on_container_move_assignment; |
| 64 | + |
| 65 | + // std::allocator_traits added this in C++17, but thrust::allocator_traits defines |
| 66 | + // it unconditionally. |
| 67 | + using is_always_equal = typename eval_if< |
| 68 | + allocator_traits_detail::has_is_always_equal<allocator_type>::value, |
| 69 | + allocator_traits_detail::nested_is_always_equal<allocator_type>, |
| 70 | + is_empty<allocator_type> |
| 71 | + >::type; |
| 72 | + |
| 73 | + template <typename U> |
| 74 | + using rebind_alloc = std::allocator<U>; |
| 75 | + template <typename U> |
| 76 | + using rebind_traits = allocator_traits<std::allocator<U>>; |
| 77 | + |
| 78 | + __thrust_exec_check_disable__ |
| 79 | + __host__ __device__ |
| 80 | + static pointer allocate(allocator_type &a, size_type n) |
| 81 | + { |
| 82 | + return superclass::allocate(a, n); |
| 83 | + } |
| 84 | + |
| 85 | + __thrust_exec_check_disable__ |
| 86 | + __host__ __device__ |
| 87 | + static pointer allocate(allocator_type &a, size_type n, const_void_pointer hint) |
| 88 | + { |
| 89 | + return superclass::allocate(a, n, hint); |
| 90 | + } |
| 91 | + |
| 92 | + __thrust_exec_check_disable__ |
| 93 | + __host__ __device__ |
| 94 | + static void deallocate(allocator_type &a, pointer p, size_type n) |
| 95 | + { |
| 96 | + superclass::deallocate(a, p, n); |
| 97 | + } |
| 98 | + |
| 99 | + __thrust_exec_check_disable__ |
| 100 | + template <typename U, typename ...Args> |
| 101 | + __host__ __device__ |
| 102 | + static void construct(allocator_type &a, U *p, Args&&... args) |
| 103 | + { |
| 104 | + superclass::construct(a, p, THRUST_FWD(args)...); |
| 105 | + } |
| 106 | + |
| 107 | + __thrust_exec_check_disable__ |
| 108 | + template <typename U> |
| 109 | + __host__ __device__ |
| 110 | + static void destroy(allocator_type &a, U *p) |
| 111 | + { |
| 112 | + superclass::destroy(a, p); |
| 113 | + } |
| 114 | + |
| 115 | + __thrust_exec_check_disable__ |
| 116 | + __host__ __device__ |
| 117 | + static size_type max_size(const allocator_type &a) |
| 118 | + { |
| 119 | + return superclass::max_size(a); |
| 120 | + } |
| 121 | +}; |
| 122 | + |
| 123 | +#endif // C++11 |
| 124 | + |
32 | 125 | namespace allocator_traits_detail
|
33 | 126 | {
|
34 | 127 |
|
|
0 commit comments