47 #include <type_traits> 56 template<
class T = void
57 ,
size_t N = ~size_t(0)
65 typedef T & reference ;
66 typedef typename std::add_const<T>::type & const_reference ;
67 typedef size_t size_type ;
68 typedef ptrdiff_t difference_type ;
69 typedef T value_type ;
71 typedef typename std::add_const<T>::type * const_pointer ;
73 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return N ; }
74 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty(){
return false ; }
76 template<
typename iType >
77 KOKKOS_INLINE_FUNCTION
78 reference operator[](
const iType & i )
80 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
84 template<
typename iType >
85 KOKKOS_INLINE_FUNCTION
86 const_reference operator[](
const iType & i )
const 88 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
92 KOKKOS_INLINE_FUNCTION pointer data() {
return & m_elem[0] ; }
93 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return & m_elem[0] ; }
98 Array & operator = (
const Array & ) = default ;
107 template<
class T ,
class Proxy >
108 struct Array<T,0,Proxy> {
111 typedef typename std::add_const<T>::type & reference ;
112 typedef typename std::add_const<T>::type & const_reference ;
113 typedef size_t size_type ;
114 typedef ptrdiff_t difference_type ;
115 typedef typename std::add_const<T>::type value_type ;
116 typedef typename std::add_const<T>::type * pointer ;
117 typedef typename std::add_const<T>::type * const_pointer ;
119 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return 0 ; }
120 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty() {
return true ; }
122 template<
typename iType >
123 KOKKOS_INLINE_FUNCTION
124 value_type operator[](
const iType & )
126 static_assert( std::is_integral<iType>::value ,
"Must be integer argument" );
130 template<
typename iType >
131 KOKKOS_INLINE_FUNCTION
132 value_type operator[](
const iType & )
const 134 static_assert( std::is_integral<iType>::value ,
"Must be integer argument" );
138 KOKKOS_INLINE_FUNCTION pointer data() {
return pointer(0) ; }
139 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return const_pointer(0); }
144 Array & operator = (
const Array & ) = default ;
154 struct Array<void,~size_t(0),void>
156 struct contiguous {};
161 struct Array< T , ~size_t(0) , Array<>::contiguous >
168 typedef T & reference ;
169 typedef typename std::add_const<T>::type & const_reference ;
170 typedef size_t size_type ;
171 typedef ptrdiff_t difference_type ;
172 typedef T value_type ;
173 typedef T * pointer ;
174 typedef typename std::add_const<T>::type * const_pointer ;
176 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
177 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
179 template<
typename iType >
180 KOKKOS_INLINE_FUNCTION
181 reference operator[](
const iType & i )
183 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
187 template<
typename iType >
188 KOKKOS_INLINE_FUNCTION
189 const_reference operator[](
const iType & i )
const 191 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
195 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
196 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
200 Array(
const Array & rhs ) = delete ;
207 KOKKOS_INLINE_FUNCTION
208 Array & operator = (
const Array & rhs )
210 const size_t n = std::min( m_size , rhs.size() );
211 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
215 template<
size_t N ,
class P >
216 KOKKOS_INLINE_FUNCTION
219 const size_t n = std::min( m_size , rhs.size() );
220 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
224 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type = 0 )
225 : m_elem(arg_ptr), m_size(arg_size) {}
229 struct Array< T , ~size_t(0) , Array<>::strided >
237 typedef T & reference ;
238 typedef typename std::add_const<T>::type & const_reference ;
239 typedef size_t size_type ;
240 typedef ptrdiff_t difference_type ;
241 typedef T value_type ;
242 typedef T * pointer ;
243 typedef typename std::add_const<T>::type * const_pointer ;
245 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
246 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
248 template<
typename iType >
249 KOKKOS_INLINE_FUNCTION
250 reference operator[](
const iType & i )
252 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
253 return m_elem[i*m_stride];
256 template<
typename iType >
257 KOKKOS_INLINE_FUNCTION
258 const_reference operator[](
const iType & i )
const 260 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
261 return m_elem[i*m_stride];
264 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
265 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
269 Array(
const Array & ) = delete ;
277 KOKKOS_INLINE_FUNCTION
278 Array & operator = (
const Array & rhs )
280 const size_t n = std::min( m_size , rhs.size() );
281 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
285 template<
size_t N ,
class P >
286 KOKKOS_INLINE_FUNCTION
289 const size_t n = std::min( m_size , rhs.size() );
290 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
294 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type arg_stride )
295 : m_elem(arg_ptr), m_size(arg_size), m_stride(arg_stride) {}
Derived from the C++17 'std::array'. Dropping the iterator interface.