39 #ifndef ECUDA_TYPE_TRAITS_HPP
40 #define ECUDA_TYPE_TRAITS_HPP
46 #ifdef ECUDA_CPP11_AVAILABLE
47 #include <type_traits>
51 template<
typename T>
using add_const = std::add_const<T>;
52 template<
typename T>
using remove_const = std::remove_const<T>;
53 template<
typename T,
typename U>
using is_same = std::is_same<T,U>;
54 template<
typename T>
using add_lvalue_reference = std::add_lvalue_reference<T>;
63 template<
bool B,
typename T>
using enable_if = std::enable_if<B,T>;
65 typedef std::true_type true_type;
66 typedef std::false_type false_type;
68 template<
typename T>
using is_integral = std::is_integral<T>;
90 template<
typename T>
using is_const = std::is_const<T>;
92 template<
typename T>
using add_pointer = std::add_pointer<T>;
107 template<
typename T>
struct add_const {
typedef const T type; };
108 template<
typename T>
struct add_const<T&> {
typedef const T& type; };
110 template<
typename T>
struct remove_const {
typedef T type; };
111 template<
typename T>
struct remove_const<const T> {
typedef T type; };
113 template<
typename T,
typename U>
struct is_same {
enum { value = 0 }; };
114 template<
typename T>
struct is_same<T,T> {
enum { value = 1 }; };
116 template<
typename T>
struct remove_reference {
typedef T type; };
117 template<
typename T>
struct remove_reference<T&> {
typedef T type; };
118 #ifdef ECUDA_CPP11_AVAILABLE
119 template<
typename T>
struct remove_reference<T&&> {
typedef T type; };
122 template<
typename T>
struct add_lvalue_reference {
typedef T& type; };
123 template<
typename T>
struct add_lvalue_reference<T&> {
typedef T& type; };
125 template<
bool B,
typename T,
typename F>
struct conditional {
typedef T type; };
126 template<
typename T,
typename F>
struct conditional<false,T,F> {
typedef F type; };
128 template<
bool B,
typename T=
void>
struct enable_if {};
129 template<
typename T>
struct enable_if<true,T> {
typedef T type; };
131 template<
typename T,T v>
132 struct integral_constant {
133 static const T value = v;
134 typedef T value_type;
135 typedef integral_constant<T,v> type;
136 operator T() {
return v; }
139 typedef integral_constant<bool,true> true_type;
140 typedef integral_constant<bool,false> false_type;
142 template<
typename T>
struct is_integral {
typedef false_type type; };
143 template<>
struct is_integral<bool> {
typedef true_type type; };
144 template<>
struct is_integral<char> {
typedef true_type type; };
145 template<>
struct is_integral<signed char> {
typedef true_type type; };
146 template<>
struct is_integral<unsigned char> {
typedef true_type type; };
147 #ifdef _GLIBCXX_USE_WCHAR_T
148 template<>
struct is_integral<wchar_t> {
typedef true_type type; };
150 #ifdef ECUDA_CPP11_AVAILABLE
151 template<>
struct is_integral<char16_t> {
typedef true_type type; };
152 template<>
struct is_integral<char32_t> {
typedef true_type type; };
154 template<>
struct is_integral<short> {
typedef true_type type; };
155 template<>
struct is_integral<unsigned short> {
typedef true_type type; };
156 template<>
struct is_integral<int> {
typedef true_type type; };
157 template<>
struct is_integral<unsigned int> {
typedef true_type type; };
158 template<>
struct is_integral<long> {
typedef true_type type; };
159 template<>
struct is_integral<unsigned long> {
typedef true_type type; };
160 template<>
struct is_integral<long long> {
typedef true_type type; };
161 template<>
struct is_integral<unsigned long long> {
typedef true_type type; };
163 template<
typename T>
struct is_const : false_type {};
164 template<
typename T>
struct is_const<const T> : true_type {};
166 template<
typename T>
struct add_pointer {
typedef typename remove_reference<T>::type* type; };
169 template<
typename T>
struct remove_pointer {
typedef T type; };
170 template<
typename T>
struct remove_pointer<T*> {
typedef T type; };
171 template<
typename T>
struct remove_pointer<T*
const> {
typedef T type; };
172 template<
typename T>
struct remove_pointer<T*
volatile> {
typedef T type; };
173 template<
typename T>
struct remove_pointer<T*
const volatile> {
typedef T type; };
184 template<
typename T,
typename P>
class padded_ptr;
185 template<
typename T>
class shared_ptr;
186 template<
typename T,
typename P>
class striding_ptr;
187 template<
typename T,
typename P>
class unique_ptr;
188 template<
typename T,
typename P>
class striding_padded_ptr;
201 template<
typename T,
typename U>
__HOST__ __DEVICE__ T naked_cast( U* ptr ) {
return reinterpret_cast<T
>(ptr); }
204 template<
typename T,
typename U,
typename V>
__HOST__ __DEVICE__ T naked_cast(
const unique_ptr<U,V>& ptr ) {
return naked_cast<T>(ptr.get()); }
205 template<
typename T,
typename U>
__HOST__ __DEVICE__ T naked_cast(
const shared_ptr<U>& ptr ) {
return naked_cast<T>(ptr.get()); }
206 template<
typename T,
typename U,
typename V>
__HOST__ __DEVICE__ T naked_cast(
const padded_ptr<U,V>& ptr ) {
return naked_cast<T>(ptr.get()); }
207 template<
typename T,
typename U,
typename V>
__HOST__ __DEVICE__ T naked_cast(
const striding_ptr<U,V>& ptr ) {
return naked_cast<T>(ptr.get()); }
224 template<
typename T>
struct make_unmanaged;
225 template<
typename T>
struct make_unmanaged< T* > {
typedef T* type; };
226 template<
typename T>
struct make_unmanaged< const T* > {
typedef const T* type; };
229 template<
typename T,
typename U>
struct make_unmanaged< unique_ptr<T,U> > {
typedef typename unique_ptr<T,U>::pointer type; };
230 template<
typename T,
typename U>
struct make_unmanaged< const unique_ptr<T,U> > {
typedef typename unique_ptr<T,U>::pointer type; };
231 template<
typename T>
struct make_unmanaged< shared_ptr<T> > {
typedef typename ecuda::add_pointer<T>::type type; };
232 template<
typename T>
struct make_unmanaged< const shared_ptr<T> > {
typedef typename ecuda::add_pointer<T>::type type; };
233 template<
typename T,
typename U>
struct make_unmanaged< padded_ptr<T,U> > {
typedef padded_ptr<T,typename make_unmanaged<U>::type> type; };
234 template<
typename T,
typename U>
struct make_unmanaged< const padded_ptr<T,U> > {
typedef padded_ptr<T,typename make_unmanaged<U>::type> type; };
235 template<
typename T,
typename U>
struct make_unmanaged< striding_ptr<T,U> > {
typedef striding_ptr<T,typename make_unmanaged<U>::type> type; };
236 template<
typename T,
typename U>
struct make_unmanaged< const striding_ptr<T,U> > {
typedef striding_ptr<T,typename make_unmanaged<U>::type> type; };
237 template<
typename T,
typename U>
struct make_unmanaged< striding_padded_ptr<T,U> > {
typedef striding_padded_ptr<T,typename make_unmanaged<U>::type> type; };
238 template<
typename T,
typename U>
struct make_unmanaged< const striding_padded_ptr<T,U> > {
typedef striding_padded_ptr<T,typename make_unmanaged<U>::type> type; };
256 template<
typename T>
__HOST__ __DEVICE__ inline typename make_unmanaged<T*>::type unmanaged_cast( T* ptr ) {
return ptr; }
260 template<
typename T,
typename U>
262 typename make_unmanaged<U>::type unmanaged_cast(
const unique_ptr<T,U>& ptr )
264 return typename make_unmanaged<U>::type( ptr.get() );
269 typename make_unmanaged< shared_ptr<T> >::type
270 unmanaged_cast(
const shared_ptr<T>& ptr )
272 return typename make_unmanaged< shared_ptr<T> >::type( ptr.get() );
275 template<
typename T,
typename U>
277 padded_ptr<T,typename make_unmanaged<U>::type>
278 unmanaged_cast(
const padded_ptr<T,U>& ptr )
281 typename make_unmanaged<U>::type mp = unmanaged_cast( ptr.get() );
282 return padded_ptr<T,typename make_unmanaged<U>::type>( mp, ptr.get_pitch() );
285 template<
typename T,
typename U>
287 striding_ptr<T,typename make_unmanaged<U>::type>
288 unmanaged_cast(
const striding_ptr<T,U>& ptr )
290 typename make_unmanaged<U>::type mp = unmanaged_cast( ptr.get() );
291 return striding_ptr<T,typename make_unmanaged<U>::type>( mp, ptr.get_stride() );
294 template<
typename T,
typename U>
296 striding_padded_ptr<T,typename make_unmanaged<U>::type>
297 unmanaged_cast(
const striding_padded_ptr<T,U>& ptr )
299 typename make_unmanaged<U>::type mp = unmanaged_cast( ptr.get() );
300 return striding_padded_ptr<T,typename make_unmanaged<U>::type>( mp, ptr.get_stride() );
315 template<
typename T>
struct make_const;
316 template<
typename T>
struct make_const< T* > {
typedef const T* type; };
317 template<
typename T>
struct make_const< const T* > {
typedef const T* type; };
320 template<
typename T,
typename U>
struct make_const< unique_ptr<T,U> > {
typedef unique_ptr<const T,typename make_const<U>::type> type; };
321 template<
typename T,
typename U>
struct make_const< unique_ptr<const T,U> > {
typedef unique_ptr<const T,typename make_const<U>::type> type; };
322 template<
typename T>
struct make_const< shared_ptr<T> > {
typedef shared_ptr<const T> type; };
323 template<
typename T>
struct make_const< shared_ptr<const T> > {
typedef shared_ptr<const T> type; };
324 template<
typename T,
typename U>
struct make_const< padded_ptr<T,U> > {
typedef padded_ptr<const T,typename make_const<U>::type> type; };
325 template<
typename T,
typename U>
struct make_const< padded_ptr<const T,U> > {
typedef padded_ptr<const T,typename make_const<U>::type> type; };
326 template<
typename T,
typename U>
struct make_const< striding_ptr<T,U> > {
typedef striding_ptr<const T,typename make_const<U>::type> type; };
327 template<
typename T,
typename U>
struct make_const< striding_ptr<const T,U> > {
typedef striding_ptr<const T,typename make_const<U>::type> type; };
329 template<
typename T,
typename U>
struct make_const< striding_padded_ptr<T,U> > {
typedef striding_padded_ptr<const T,typename make_const<U>::type> type; };
330 template<
typename T,
typename U>
struct make_const< striding_padded_ptr<const T,U> > {
typedef striding_padded_ptr<const T,typename make_const<U>::type> type; };
337 template<
typename T>
struct make_unmanaged_const {
typedef typename make_unmanaged<typename make_const<T>::type>::type type; };