47 #include <type_traits> 57 template<
class T = void
58 ,
size_t N = ~size_t(0)
66 typedef T & reference ;
67 typedef typename std::add_const<T>::type & const_reference ;
68 typedef size_t size_type ;
69 typedef ptrdiff_t difference_type ;
70 typedef T value_type ;
72 typedef typename std::add_const<T>::type * const_pointer ;
74 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return N ; }
75 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty(){
return false ; }
77 template<
typename iType >
78 KOKKOS_INLINE_FUNCTION
79 reference operator[](
const iType & i )
81 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
85 template<
typename iType >
86 KOKKOS_INLINE_FUNCTION
87 const_reference operator[](
const iType & i )
const 89 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
93 KOKKOS_INLINE_FUNCTION pointer data() {
return & m_elem[0] ; }
94 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return & m_elem[0] ; }
99 Array & operator = (
const Array & ) = default ;
108 template<
class T ,
class Proxy >
109 struct Array<T,0,Proxy> {
112 typedef typename std::add_const<T>::type & reference ;
113 typedef typename std::add_const<T>::type & const_reference ;
114 typedef size_t size_type ;
115 typedef ptrdiff_t difference_type ;
116 typedef typename std::add_const<T>::type value_type ;
117 typedef typename std::add_const<T>::type * pointer ;
118 typedef typename std::add_const<T>::type * const_pointer ;
120 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return 0 ; }
121 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty() {
return true ; }
123 template<
typename iType >
124 KOKKOS_INLINE_FUNCTION
125 value_type operator[](
const iType & )
127 static_assert( std::is_integral<iType>::value ,
"Must be integer argument" );
131 template<
typename iType >
132 KOKKOS_INLINE_FUNCTION
133 value_type operator[](
const iType & )
const 135 static_assert( std::is_integral<iType>::value ,
"Must be integer argument" );
139 KOKKOS_INLINE_FUNCTION pointer data() {
return pointer(0) ; }
140 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return const_pointer(0); }
144 Array(
const Array & ) = default ;
145 Array & operator = (
const Array & ) = default ;
155 struct Array<void,~size_t(0),void>
157 struct contiguous {};
162 struct Array< T , ~size_t(0) , Array<>::contiguous >
169 typedef T & reference ;
170 typedef typename std::add_const<T>::type & const_reference ;
171 typedef size_t size_type ;
172 typedef ptrdiff_t difference_type ;
173 typedef T value_type ;
174 typedef T * pointer ;
175 typedef typename std::add_const<T>::type * const_pointer ;
177 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
178 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
180 template<
typename iType >
181 KOKKOS_INLINE_FUNCTION
182 reference operator[](
const iType & i )
184 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
188 template<
typename iType >
189 KOKKOS_INLINE_FUNCTION
190 const_reference operator[](
const iType & i )
const 192 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
196 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
197 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
201 Array(
const Array & rhs ) = delete ;
208 KOKKOS_INLINE_FUNCTION
209 Array & operator = (
const Array & rhs )
211 const size_t n = std::min( m_size , rhs.size() );
212 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
216 template<
size_t N ,
class P >
217 KOKKOS_INLINE_FUNCTION
218 Array & operator = (
const Array<T,N,P> & rhs )
220 const size_t n = std::min( m_size , rhs.size() );
221 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
225 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type = 0 )
226 : m_elem(arg_ptr), m_size(arg_size) {}
230 struct Array< T , ~size_t(0) , Array<>::strided >
238 typedef T & reference ;
239 typedef typename std::add_const<T>::type & const_reference ;
240 typedef size_t size_type ;
241 typedef ptrdiff_t difference_type ;
242 typedef T value_type ;
243 typedef T * pointer ;
244 typedef typename std::add_const<T>::type * const_pointer ;
246 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
247 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
249 template<
typename iType >
250 KOKKOS_INLINE_FUNCTION
251 reference operator[](
const iType & i )
253 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
254 return m_elem[i*m_stride];
257 template<
typename iType >
258 KOKKOS_INLINE_FUNCTION
259 const_reference operator[](
const iType & i )
const 261 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
262 return m_elem[i*m_stride];
265 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
266 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
270 Array(
const Array & ) = delete ;
278 KOKKOS_INLINE_FUNCTION
279 Array & operator = (
const Array & rhs )
281 const size_t n = std::min( m_size , rhs.size() );
282 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
286 template<
size_t N ,
class P >
287 KOKKOS_INLINE_FUNCTION
288 Array & operator = (
const Array<T,N,P> & rhs )
290 const size_t n = std::min( m_size , rhs.size() );
291 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
295 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type arg_stride )
296 : m_elem(arg_ptr), m_size(arg_size), m_stride(arg_stride) {}
Derived from the C++17 'std::array'. Dropping the iterator interface.