44 #ifndef KOKKOS_ARRAY_HPP 45 #define KOKKOS_ARRAY_HPP 47 #include <type_traits> 57 template<
class T = void
58 ,
size_t N = ~size_t(0)
69 T m_internal_implementation_private_member_data[N];
72 typedef T & reference ;
73 typedef typename std::add_const<T>::type & const_reference ;
74 typedef size_t size_type ;
75 typedef ptrdiff_t difference_type ;
76 typedef T value_type ;
78 typedef typename std::add_const<T>::type * const_pointer ;
80 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return N ; }
81 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty(){
return false ; }
83 template<
typename iType >
84 KOKKOS_INLINE_FUNCTION
85 reference operator[](
const iType & i )
87 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integral argument" );
88 return m_internal_implementation_private_member_data[i];
91 template<
typename iType >
92 KOKKOS_INLINE_FUNCTION
93 const_reference operator[](
const iType & i )
const 95 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integral argument" );
96 return m_internal_implementation_private_member_data[i];
99 KOKKOS_INLINE_FUNCTION pointer data()
101 return & m_internal_implementation_private_member_data[0];
103 KOKKOS_INLINE_FUNCTION const_pointer data()
const 105 return & m_internal_implementation_private_member_data[0];
121 template<
class T ,
class Proxy >
122 struct Array<T,0,Proxy> {
125 typedef typename std::add_const<T>::type & reference ;
126 typedef typename std::add_const<T>::type & const_reference ;
127 typedef size_t size_type ;
128 typedef ptrdiff_t difference_type ;
129 typedef typename std::add_const<T>::type value_type ;
130 typedef typename std::add_const<T>::type * pointer ;
131 typedef typename std::add_const<T>::type * const_pointer ;
133 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return 0 ; }
134 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty() {
return true ; }
136 template<
typename iType >
137 KOKKOS_INLINE_FUNCTION
138 value_type operator[](
const iType & )
140 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integer argument" );
144 template<
typename iType >
145 KOKKOS_INLINE_FUNCTION
146 value_type operator[](
const iType & )
const 148 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integer argument" );
152 KOKKOS_INLINE_FUNCTION pointer data() {
return pointer(0) ; }
153 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return const_pointer(0); }
158 Array & operator = (
const Array & ) = default ;
168 struct Array<void,~size_t(0),void>
170 struct contiguous {};
175 struct Array< T , ~size_t(0) , Array<>::contiguous >
182 typedef T & reference ;
183 typedef typename std::add_const<T>::type & const_reference ;
184 typedef size_t size_type ;
185 typedef ptrdiff_t difference_type ;
186 typedef T value_type ;
187 typedef T * pointer ;
188 typedef typename std::add_const<T>::type * const_pointer ;
190 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
191 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
193 template<
typename iType >
194 KOKKOS_INLINE_FUNCTION
195 reference operator[](
const iType & i )
197 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integral argument" );
201 template<
typename iType >
202 KOKKOS_INLINE_FUNCTION
203 const_reference operator[](
const iType & i )
const 205 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integral argument" );
209 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
210 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
214 Array(
const Array & rhs ) = delete ;
221 KOKKOS_INLINE_FUNCTION
222 Array & operator = (
const Array & rhs )
224 const size_t n = std::min( m_size , rhs.size() );
225 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
229 template<
size_t N ,
class P >
230 KOKKOS_INLINE_FUNCTION
233 const size_t n = std::min( m_size , rhs.size() );
234 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
238 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type = 0 )
239 : m_elem(arg_ptr), m_size(arg_size) {}
243 struct Array< T , ~size_t(0) , Array<>::strided >
251 typedef T & reference ;
252 typedef typename std::add_const<T>::type & const_reference ;
253 typedef size_t size_type ;
254 typedef ptrdiff_t difference_type ;
255 typedef T value_type ;
256 typedef T * pointer ;
257 typedef typename std::add_const<T>::type * const_pointer ;
259 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
260 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
262 template<
typename iType >
263 KOKKOS_INLINE_FUNCTION
264 reference operator[](
const iType & i )
266 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integral argument" );
267 return m_elem[i*m_stride];
270 template<
typename iType >
271 KOKKOS_INLINE_FUNCTION
272 const_reference operator[](
const iType & i )
const 274 static_assert( ( std::is_integral<iType>::value || std::is_enum<iType>::value ) ,
"Must be integral argument" );
275 return m_elem[i*m_stride];
278 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
279 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
283 Array(
const Array & ) = delete ;
291 KOKKOS_INLINE_FUNCTION
292 Array & operator = (
const Array & rhs )
294 const size_t n = std::min( m_size , rhs.size() );
295 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
299 template<
size_t N ,
class P >
300 KOKKOS_INLINE_FUNCTION
303 const size_t n = std::min( m_size , rhs.size() );
304 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
308 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type arg_stride )
309 : m_elem(arg_ptr), m_size(arg_size), m_stride(arg_stride) {}
Derived from the C++17 'std::array'. Dropping the iterator interface.