2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <thrust/detail/config.h>
20 #include <thrust/system/cuda/detail/detail/alignment.h>
40 typename aligned_storage<
42 alignment_of<T>::value
45 __device__ __thrust_forceinline__ const T* ptr() const
47 return reinterpret_cast<const T*>(storage.data);
50 __device__ __thrust_forceinline__ T* ptr()
52 return reinterpret_cast<T*>(storage.data);
57 __device__ __thrust_forceinline__ uninitialized<T> &operator=(const T &other)
64 __device__ __thrust_forceinline__ T& get()
69 __device__ __thrust_forceinline__ const T& get() const
74 __device__ __thrust_forceinline__ operator T& ()
79 __device__ __thrust_forceinline__ operator const T&() const
84 __thrust_forceinline__ __device__ void construct()
89 template<typename Arg>
90 __thrust_forceinline__ __device__ void construct(const Arg &a)
95 template<typename Arg1, typename Arg2>
96 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2)
98 ::new(ptr()) T(a1,a2);
101 template<typename Arg1, typename Arg2, typename Arg3>
102 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3)
104 ::new(ptr()) T(a1,a2,a3);
107 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4>
108 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4)
110 ::new(ptr()) T(a1,a2,a3,a4);
113 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
114 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5)
116 ::new(ptr()) T(a1,a2,a3,a4,a5);
119 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
120 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6)
122 ::new(ptr()) T(a1,a2,a3,a4,a5,a6);
125 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7>
126 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7)
128 ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7);
131 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7, typename Arg8>
132 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7, const Arg8 &a8)
134 ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7,a8);
137 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7, typename Arg8, typename Arg9>
138 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7, const Arg8 &a8, const Arg9 &a9)
140 ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7,a8,a9);
143 template<typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename Arg7, typename Arg8, typename Arg9, typename Arg10>
144 __thrust_forceinline__ __device__ void construct(const Arg1 &a1, const Arg2 &a2, const Arg3 &a3, const Arg4 &a4, const Arg5 &a5, const Arg6 &a6, const Arg7 &a7, const Arg8 &a8, const Arg9 &a9, const Arg10 &a10)
146 ::new(ptr()) T(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);
149 __thrust_forceinline__ __device__ void destroy()
157 template<typename T, std::size_t N>
158 class uninitialized_array
161 typedef T value_type;
162 typedef T& reference;
163 typedef const T& const_reference;
165 typedef const T* const_pointer;
166 typedef pointer iterator;
167 typedef const_pointer const_iterator;
168 typedef std::size_t size_type;
170 __thrust_forceinline__ __device__ iterator begin()
175 __thrust_forceinline__ __device__ const_iterator begin() const
180 __thrust_forceinline__ __device__ iterator end()
182 return begin() + size();
185 __thrust_forceinline__ __device__ const_iterator end() const
187 return begin() + size();
190 __thrust_forceinline__ __device__ const_iterator cbegin() const
195 __thrust_forceinline__ __device__ const_iterator cend() const
200 __thrust_forceinline__ __device__ size_type size() const
205 __thrust_forceinline__ __device__ bool empty() const
210 __thrust_forceinline__ __device__ T* data()
215 __thrust_forceinline__ __device__ const T* data() const
221 __thrust_forceinline__ __device__ reference operator[](size_type n)
226 __thrust_forceinline__ __device__ const_reference operator[](size_type n) const
231 __thrust_forceinline__ __device__ reference front()
236 __thrust_forceinline__ __device__ const_reference front() const
241 __thrust_forceinline__ __device__ reference back()
243 return data()[size() - size_type(1)];
246 __thrust_forceinline__ __device__ const_reference back() const
248 return data()[size() - size_type(1)];
252 uninitialized<T[N]> impl;