47 #include <type_traits> 55 template<
class T = void
56 ,
size_t N = ~size_t(0)
64 typedef T & reference ;
65 typedef typename std::add_const<T>::type & const_reference ;
66 typedef size_t size_type ;
67 typedef ptrdiff_t difference_type ;
68 typedef T value_type ;
70 typedef typename std::add_const<T>::type * const_pointer ;
72 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return N ; }
73 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty(){
return false ; }
75 template<
typename iType >
76 KOKKOS_INLINE_FUNCTION
77 reference operator[](
const iType & i )
79 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
83 template<
typename iType >
84 KOKKOS_INLINE_FUNCTION
85 const_reference operator[](
const iType & i )
const 87 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
91 KOKKOS_INLINE_FUNCTION pointer data() {
return & m_elem[0] ; }
92 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return & m_elem[0] ; }
97 Array & operator = (
const Array & ) = default ;
106 template<
class T ,
class Proxy >
107 struct Array<T,0,Proxy> {
110 typedef typename std::add_const<T>::type & reference ;
111 typedef typename std::add_const<T>::type & const_reference ;
112 typedef size_t size_type ;
113 typedef ptrdiff_t difference_type ;
114 typedef typename std::add_const<T>::type value_type ;
115 typedef typename std::add_const<T>::type * pointer ;
116 typedef typename std::add_const<T>::type * const_pointer ;
118 KOKKOS_INLINE_FUNCTION
static constexpr size_type size() {
return 0 ; }
119 KOKKOS_INLINE_FUNCTION
static constexpr
bool empty() {
return true ; }
121 template<
typename iType >
122 KOKKOS_INLINE_FUNCTION
123 value_type operator[](
const iType & )
125 static_assert( std::is_integral<iType>::value ,
"Must be integer argument" );
129 template<
typename iType >
130 KOKKOS_INLINE_FUNCTION
131 value_type operator[](
const iType & )
const 133 static_assert( std::is_integral<iType>::value ,
"Must be integer argument" );
137 KOKKOS_INLINE_FUNCTION pointer data() {
return pointer(0) ; }
138 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return const_pointer(0); }
143 Array & operator = (
const Array & ) = default ;
153 struct Array<void,~size_t(0),void>
155 struct contiguous {};
160 struct Array< T , ~size_t(0) , Array<>::contiguous >
167 typedef T & reference ;
168 typedef typename std::add_const<T>::type & const_reference ;
169 typedef size_t size_type ;
170 typedef ptrdiff_t difference_type ;
171 typedef T value_type ;
172 typedef T * pointer ;
173 typedef typename std::add_const<T>::type * const_pointer ;
175 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
176 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
178 template<
typename iType >
179 KOKKOS_INLINE_FUNCTION
180 reference operator[](
const iType & i )
182 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
186 template<
typename iType >
187 KOKKOS_INLINE_FUNCTION
188 const_reference operator[](
const iType & i )
const 190 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
194 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
195 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
199 Array(
const Array & rhs ) = delete ;
206 KOKKOS_INLINE_FUNCTION
207 Array & operator = (
const Array & rhs )
209 const size_t n = std::min( m_size , rhs.size() );
210 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
214 template<
size_t N ,
class P >
215 KOKKOS_INLINE_FUNCTION
218 const size_t n = std::min( m_size , rhs.size() );
219 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
223 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type = 0 )
224 : m_elem(arg_ptr), m_size(arg_size) {}
228 struct Array< T , ~size_t(0) , Array<>::strided >
236 typedef T & reference ;
237 typedef typename std::add_const<T>::type & const_reference ;
238 typedef size_t size_type ;
239 typedef ptrdiff_t difference_type ;
240 typedef T value_type ;
241 typedef T * pointer ;
242 typedef typename std::add_const<T>::type * const_pointer ;
244 KOKKOS_INLINE_FUNCTION constexpr size_type size()
const {
return m_size ; }
245 KOKKOS_INLINE_FUNCTION constexpr
bool empty()
const {
return 0 != m_size ; }
247 template<
typename iType >
248 KOKKOS_INLINE_FUNCTION
249 reference operator[](
const iType & i )
251 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
252 return m_elem[i*m_stride];
255 template<
typename iType >
256 KOKKOS_INLINE_FUNCTION
257 const_reference operator[](
const iType & i )
const 259 static_assert( std::is_integral<iType>::value ,
"Must be integral argument" );
260 return m_elem[i*m_stride];
263 KOKKOS_INLINE_FUNCTION pointer data() {
return m_elem ; }
264 KOKKOS_INLINE_FUNCTION const_pointer data()
const {
return m_elem ; }
268 Array(
const Array & ) = delete ;
276 KOKKOS_INLINE_FUNCTION
277 Array & operator = (
const Array & rhs )
279 const size_t n = std::min( m_size , rhs.size() );
280 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
284 template<
size_t N ,
class P >
285 KOKKOS_INLINE_FUNCTION
288 const size_t n = std::min( m_size , rhs.size() );
289 for (
size_t i = 0 ; i < n ; ++i ) m_elem[i] = rhs[i] ;
293 KOKKOS_INLINE_FUNCTION constexpr Array( pointer arg_ptr , size_type arg_size , size_type arg_stride )
294 : m_elem(arg_ptr), m_size(arg_size), m_stride(arg_stride) {}
Derived from the C++17 'std::array'. Dropping the iterator interface.