#ifndef FIXED_ARRAY_H #define FIXED_ARRAY_H #include #include // Fixed array template class fixed_array: public boost::numeric::ublas::storage_array > { typedef fixed_array self_type; public: typedef std::size_t size_type; typedef std::size_t difference_type; typedef T value_type; typedef const T &const_reference; typedef T &reference; typedef const T *const_pointer; typedef T *pointer; typedef const_pointer const_iterator; typedef pointer iterator; // Construction and destruction BOOST_UBLAS_INLINE fixed_array () { // size 0 - use bounded_vector to default construct with size N } explicit BOOST_UBLAS_INLINE fixed_array (size_type size) { BOOST_UBLAS_CHECK (size == N, boost::numeric::ublas::bad_size ()); // data_ (an array) elements are already default constructed } BOOST_UBLAS_INLINE fixed_array (size_type size, const value_type &init) { BOOST_UBLAS_CHECK (size == N, boost::numeric::ublas::bad_size ()); // ISSUE elements should be value constructed here, but we must fill instead as already default constructed std::fill (begin(), end(), init) ; } BOOST_UBLAS_INLINE fixed_array (const fixed_array &c) { // ISSUE elements should be copy constructed here, but we must copy instead as already default constructed std::copy (c.begin(), c.end(), begin()); } // Resizing BOOST_UBLAS_INLINE void resize (size_type size) { BOOST_UBLAS_CHECK (size == N, boost::numeric::ublas::bad_size ()); } BOOST_UBLAS_INLINE void resize (size_type size, value_type init) { BOOST_UBLAS_CHECK (size == N, boost::numeric::ublas::bad_size ()); } // Random Access Container BOOST_UBLAS_INLINE size_type max_size () const { return N; } BOOST_UBLAS_INLINE bool empty () const { return N > 0; } BOOST_UBLAS_INLINE size_type size () const { return N; } // Element access BOOST_UBLAS_INLINE const_reference operator [] (size_type i) const { BOOST_UBLAS_CHECK (i < N, boost::numeric::ublas::bad_index ()); return data_ [i]; } BOOST_UBLAS_INLINE reference operator [] (size_type i) { BOOST_UBLAS_CHECK (i < N, boost::numeric::ublas::bad_index ()); return data_ [i]; } // Assignment BOOST_UBLAS_INLINE fixed_array &operator = (const fixed_array &a) { if (this != &a) { std::copy (a.data_, a.data_ + N, data_); } return *this; } BOOST_UBLAS_INLINE fixed_array &assign_temporary (fixed_array &a) { *this = a; return *this; } // Swapping BOOST_UBLAS_INLINE void swap (fixed_array &a) { if (this != &a) { std::swap_ranges (data_, data_ + N, a.data_); } } BOOST_UBLAS_INLINE friend void swap (fixed_array &a1, fixed_array &a2) { a1.swap (a2); } BOOST_UBLAS_INLINE const_iterator begin () const { return data_; } BOOST_UBLAS_INLINE const_iterator end () const { return data_ + N; } BOOST_UBLAS_INLINE iterator begin () { return data_; } BOOST_UBLAS_INLINE iterator end () { return data_ + N; } // Reverse iterators typedef std::reverse_iterator const_reverse_iterator; typedef std::reverse_iterator reverse_iterator; BOOST_UBLAS_INLINE const_reverse_iterator rbegin () const { return const_reverse_iterator (end ()); } BOOST_UBLAS_INLINE const_reverse_iterator rend () const { return const_reverse_iterator (begin ()); } BOOST_UBLAS_INLINE reverse_iterator rbegin () { return reverse_iterator (end ()); } BOOST_UBLAS_INLINE reverse_iterator rend () { return reverse_iterator (begin ()); } #if 0 private: // Serialization friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) { serialization::collection_size_type s(size_); ar & serialization::make_nvp("size", s); if ( Archive::is_loading::value ) { if (s > N) boost::numeric::ublas::bad_size("too large size in fixed_array::load()\n").raise(); resize(s); } ar & serialization::make_array(data_, s); } #endif private: // size_type size_; value_type data_ [N]; }; #endif