...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::array — STL compliant container wrapper for arrays of constant size
// In header: <boost/array.hpp> template<typename T, std::size_t N> class array { public: // types typedef T value_type; typedef T* iterator; typedef const T* const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef T& reference; typedef const T& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; // static constants static const size_type static_size = N; // construct/copy/destruct template<typename U> array& operator=(const array<U, N>&); // iterator support iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; // reverse iterator support reverse_iterator rbegin(); const_reverse_iterator rbegin() const; reverse_iterator rend(); const_reverse_iterator rend() const; // capacity size_type size(); bool empty(); size_type max_size(); // element access reference operator[](size_type); const_reference operator[](size_type) const; reference at(size_type); const_reference at(size_type) const; reference front(); const_reference front() const; reference back(); const_reference back() const; const T* data() const; T* c_array(); // modifiers void swap(array<T, N>&); void assign(const T&); // public data members T elems[N]; }; // specialized algorithms template<typename T, std::size_t N> void swap(array<T, N>&, array<T, N>&); // comparisons template<typename T, std::size_t N> bool operator==(const array<T, N>&, const array<T, N>&); template<typename T, std::size_t N> bool operator!=(const array<T, N>&, const array<T, N>&); template<typename T, std::size_t N> bool operator<(const array<T, N>&, const array<T, N>&); template<typename T, std::size_t N> bool operator>(const array<T, N>&, const array<T, N>&); template<typename T, std::size_t N> bool operator<=(const array<T, N>&, const array<T, N>&); template<typename T, std::size_t N> bool operator>=(const array<T, N>&, const array<T, N>&);
array
element accessreference operator[](size_type i); const_reference operator[](size_type i) const;
Requires: |
i < N |
Returns: |
element with index i
|
Throws: |
will not throw. |
reference at(size_type i); const_reference at(size_type i) const;
Returns: |
element with index i
|
Throws: |
std::range_error if i >= N
|
reference front(); const_reference front() const;
Requires: |
N > 0 |
Returns: |
the first element |
Throws: |
will not throw |
reference back(); const_reference back() const;
Requires: |
N > 0 |
Returns: |
the last element |
Throws: |
will not throw |
const T* data() const;
Returns: |
elems |
Throws: |
will not throw |
T* c_array();
Returns: |
elems |
Throws: |
will not throw |
array
comparisonstemplate<typename T, std::size_t N> bool operator==(const array<T, N>& x, const array<T, N>& y);
template<typename T, std::size_t N> bool operator!=(const array<T, N>& x, const array<T, N>& y);
Returns: |
!(x == y) |
template<typename T, std::size_t N> bool operator<(const array<T, N>& x, const array<T, N>& y);
template<typename T, std::size_t N> bool operator>(const array<T, N>& x, const array<T, N>& y);
Returns: |
y < x |
template<typename T, std::size_t N> bool operator<=(const array<T, N>& x, const array<T, N>& y);
Returns: |
!(y < x) |
template<typename T, std::size_t N> bool operator>=(const array<T, N>& x, const array<T, N>& y);
Returns: |
!(x < y) |