31#ifndef BOOST_ARRAY_HPP_OPENFPM
32#define BOOST_ARRAY_HPP_OPENFPM
34#include <boost/detail/workaround.hpp>
36#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
38# pragma warning(disable:4996)
39# pragma warning(disable:4510)
40# pragma warning(disable:4610)
45#include <boost/assert.hpp>
46#include <boost/static_assert.hpp>
47#include <boost/swap.hpp>
50#include <boost/throw_exception.hpp>
54#include <boost/config.hpp>
59 template<
class T, std::
size_t N,
typename ids_type = std::
size_t>
68 typedef const T* const_iterator;
70 typedef const T& const_reference;
71 typedef ids_type size_type;
72 typedef std::ptrdiff_t difference_type;
75 iterator begin() {
return elems; }
76 const_iterator begin()
const {
return elems; }
77 const_iterator cbegin()
const {
return elems; }
79 iterator end() {
return elems+N; }
80 const_iterator end()
const {
return elems+N; }
81 const_iterator cend()
const {
return elems+N; }
84#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
85 typedef std::reverse_iterator<iterator> reverse_iterator;
86 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
87#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
88 typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
89 value_type, reference, iterator, difference_type> reverse_iterator;
90 typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
91 value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
94 typedef std::reverse_iterator<iterator,T> reverse_iterator;
95 typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
98 reverse_iterator rbegin() {
return reverse_iterator(end()); }
99 const_reverse_iterator rbegin()
const {
100 return const_reverse_iterator(end());
102 const_reverse_iterator crbegin()
const {
103 return const_reverse_iterator(end());
106 reverse_iterator rend() {
return reverse_iterator(begin()); }
107 const_reverse_iterator rend()
const {
108 return const_reverse_iterator(begin());
110 const_reverse_iterator crend()
const {
111 return const_reverse_iterator(begin());
115 __device__ __host__ reference operator[](size_type i)
117 return BOOST_ASSERT_MSG( i < N,
"out of range" ), elems[i];
120 __device__ __host__ const_reference operator[](size_type i)
const
122 return BOOST_ASSERT_MSG( i < N,
"out of range" ), elems[i];
126 reference at(size_type i) {
return rangecheck(i), elems[i]; }
127 const_reference at(size_type i)
const {
return rangecheck(i), elems[i]; }
135 BOOST_CONSTEXPR const_reference front()
const
145 BOOST_CONSTEXPR const_reference back()
const
151 static BOOST_CONSTEXPR size_type size() {
return N; }
152 static BOOST_CONSTEXPR
bool empty() {
return false; }
153 static BOOST_CONSTEXPR size_type max_size() {
return N; }
154 enum { static_size = N };
158 for (size_type i = 0; i < N; ++i)
159 boost::swap(elems[i],y.elems[i]);
163 __device__ __host__
const T* data()
const {
return elems; }
164 __device__ __host__ T* data() {
return elems; }
167 T* c_array() {
return elems; }
170 template <
typename T2>
172 std::copy(rhs.begin(),rhs.end(), begin());
177 void assign (
const T& value) { fill ( value ); }
178 void fill (
const T& value)
180 std::fill_n(begin(),size(),value);
184 static BOOST_CONSTEXPR
bool rangecheck (size_type i) {
185 return i > size() ? boost::throw_exception(std::out_of_range (
"array<>: index out of range")), true :
true;
195 typedef T value_type;
197 typedef const T* const_iterator;
198 typedef T& reference;
199 typedef const T& const_reference;
200 typedef std::size_t size_type;
201 typedef std::ptrdiff_t difference_type;
204 iterator begin() {
return iterator(
reinterpret_cast< T *
>(
this ) ); }
205 const_iterator begin()
const {
return const_iterator(
reinterpret_cast< const T *
>(
this ) ); }
206 const_iterator cbegin()
const {
return const_iterator(
reinterpret_cast< const T *
>(
this ) ); }
208 iterator end() {
return begin(); }
209 const_iterator end()
const {
return begin(); }
210 const_iterator cend()
const {
return cbegin(); }
213#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
214 typedef std::reverse_iterator<iterator> reverse_iterator;
215 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
216#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
217 typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
218 value_type, reference, iterator, difference_type> reverse_iterator;
219 typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
220 value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
223 typedef std::reverse_iterator<iterator,T> reverse_iterator;
224 typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
227 reverse_iterator rbegin() {
return reverse_iterator(end()); }
228 const_reverse_iterator rbegin()
const {
229 return const_reverse_iterator(end());
231 const_reverse_iterator crbegin()
const {
232 return const_reverse_iterator(end());
235 reverse_iterator rend() {
return reverse_iterator(begin()); }
236 const_reverse_iterator rend()
const {
237 return const_reverse_iterator(begin());
239 const_reverse_iterator crend()
const {
240 return const_reverse_iterator(begin());
244 reference operator[](size_type )
246 return failed_rangecheck();
249 const_reference operator[](size_type )
const
251 return failed_rangecheck();
255 reference at(size_type ) {
return failed_rangecheck(); }
256 const_reference at(size_type )
const {
return failed_rangecheck(); }
261 return failed_rangecheck();
264 BOOST_CONSTEXPR const_reference front()
const
266 return failed_rangecheck();
271 return failed_rangecheck();
274 BOOST_CONSTEXPR const_reference back()
const
276 return failed_rangecheck();
280 static BOOST_CONSTEXPR size_type size() {
return 0; }
281 static BOOST_CONSTEXPR
bool empty() {
return true; }
282 static BOOST_CONSTEXPR size_type max_size() {
return 0; }
283 enum { static_size = 0 };
289 const T* data()
const {
return 0; }
290 T* data() {
return 0; }
293 T* c_array() {
return 0; }
296 template <
typename T2>
302 void assign (
const T& value) { fill ( value ); }
303 void fill (
const T& ) {}
306 static reference failed_rangecheck () {
307 std::out_of_range e(
"attempt to access element of an empty array");
308 boost::throw_exception(e);
309#if defined(BOOST_NO_EXCEPTIONS) || (!defined(BOOST_MSVC) && !defined(__PATHSCALE__))
315 static T placeholder;
322 template<
class T, std::
size_t N>
324 return std::equal(x.begin(), x.end(), y.begin());
326 template<
class T, std::
size_t N>
327 bool operator< (
const array_openfpm<T,N>& x,
const array_openfpm<T,N>& y) {
328 return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
330 template<
class T, std::
size_t N>
331 bool operator!= (
const array_openfpm<T,N>& x,
const array_openfpm<T,N>& y) {
334 template<
class T, std::
size_t N>
335 bool operator> (
const array_openfpm<T,N>& x,
const array_openfpm<T,N>& y) {
338 template<
class T, std::
size_t N>
339 bool operator<= (
const array_openfpm<T,N>& x,
const array_openfpm<T,N>& y) {
342 template<
class T, std::
size_t N>
343 bool operator>= (
const array_openfpm<T,N>& x,
const array_openfpm<T,N>& y) {
348 template<
class T, std::
size_t N>
349 inline void swap (array_openfpm<T,N>& x, array_openfpm<T,N>& y) {
353#if defined(__SUNPRO_CC)
360 template <
typename T, std::
size_t N>
struct c_array
367 template <
typename T, std::
size_t N>
374 template <
typename T, std::
size_t N>
381 template <
typename T, std::
size_t N>
388 template <
typename T, std::
size_t N>
399 template <
typename T, std::
size_t N>
400 T(&get_c_array(std::array<T,N>& arg))[N]
402 return static_cast<T(&)[N]
>(arg);
406 template <
typename T, std::
size_t N>
407 const T(&get_c_array(
const std::array<T,N>& arg))[N]
409 return static_cast<T(&)[N]
>(arg);
413 template <
class It> std::size_t hash_range(It, It);
415 template<
class T, std::
size_t N>
416 std::size_t hash_value(
const array_openfpm<T,N>& arr)
418 return boost::hash_range(arr.begin(), arr.end());
421 template <
size_t Idx,
typename T,
size_t N>
423 BOOST_STATIC_ASSERT_MSG ( Idx < N,
"boost::get<>(boost::array &) index out of range" );
427 template <
size_t Idx,
typename T,
size_t N>
429 BOOST_STATIC_ASSERT_MSG ( Idx < N,
"boost::get<>(const boost::array &) index out of range" );
435#ifndef BOOST_NO_CXX11_HDR_ARRAY
438 template <
size_t Idx,
typename T,
size_t N>
440 BOOST_STATIC_ASSERT_MSG ( Idx < N,
"std::get<>(boost::array &) index out of range" );
444 template <
size_t Idx,
typename T,
size_t N>
446 BOOST_STATIC_ASSERT_MSG ( Idx < N,
"std::get<>(const boost::array &) index out of range" );
452#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)