Array
Boost.Array Library
Public Attributes | List of all members
boost::array< T, N > Class Template Reference

A container that encapsulates fixed size arrays. More...

#include <array.hpp>

Public Types

Types
typedef T value_type
 The array value type. More...
 
typedef T * iterator
 Iterator to C-style array, i.e. a pointer. More...
 
typedef const T * const_iterator
 Constant iterator to array, i.e. a pointer. More...
 
typedef T & reference
 Reference to value type. More...
 
typedef const T & const_reference
 Constant reference to value type. More...
 
typedef std::size_t size_type
 Type used to represent array size. More...
 
typedef std::ptrdiff_t difference_type
 Type used to represent distance between iterators. More...
 
typedef std::reverse_iterator< iteratorreverse_iterator
 Reverse array iterator - std::reverse_iterator<iterator> More...
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Constant reverse array iterator - std::reverse_iterator<const_iterator> More...
 

Public Member Functions

Iterators
iterator begin ()
 Returns an iterator to the beginning. More...
 
const_iterator begin () const
 Returns a constant iterator to the beginning. More...
 
const_iterator cbegin () const
 Returns a constant iterator to the beginning. More...
 
iterator end ()
 Returns an iterator to the end. More...
 
const_iterator end () const
 Returns a constant iterator to the end. More...
 
const_iterator cend () const
 Returns a constant iterator to the end. More...
 
reverse_iterator rbegin ()
 Returns a reverse iterator to the beginning. More...
 
const_reverse_iterator rbegin () const
 Returns a constant reverse iterator to the beginning. More...
 
const_reverse_iterator crbegin () const
 Returns a reverse iterator to the beginning. More...
 
reverse_iterator rend ()
 Returns a reverse iterator to the end. More...
 
const_reverse_iterator rend () const
 Returns a constant reverse iterator to the end. More...
 
const_reverse_iterator crend () const
 Returns a constant reverse iterator to the end. More...
 
Element access
reference operator[] (size_type i)
 Access specified element. More...
 
const_reference operator[] (size_type i) const
 Access specified element. More...
 
reference at (size_type i)
 Access specified element with bounds checking. More...
 
const_reference at (size_type i) const
 Access specified element with bounds checking. More...
 
reference front ()
 Access the first array element. More...
 
constexpr const_reference front () const
 Access the first array element. More...
 
reference back ()
 Access the last array element. More...
 
constexpr const_reference back () const
 Access the last array element. More...
 
Swap
void swap (array< T, N > &y)
 Swaps the container contents. More...
 
Direct access to data
const T * data () const
 Direct access to the underlying array. More...
 
T * data ()
 Direct access to the underlying array. More...
 
T * c_array ()
 Direct access to the underlying array. More...
 
Assignment with type conversion
template<typename T2 >
array< T, N > & operator= (const array< T2, N > &rhs)
 Overwrites element of the array with elements of another array. More...
 
void assign (const T &value)
 Assign one value to all elements. More...
 
void fill (const T &value)
 Assign one value to all elements. More...
 

Static Public Member Functions

Capacity
static constexpr size_type size ()
 Returns the number of elements. More...
 
static constexpr bool empty ()
 Checks whether the container is empty. More...
 
static constexpr size_type max_size ()
 Returns the maximum possible number of elements. More...
 
Check range
static constexpr bool rangecheck (size_type i)
 Check range. More...
 

Public Attributes

elems [N]
 Underlying fixed-size array of elements of type T. More...
 

Detailed Description

template<class T, std::size_t N>
class boost::array< T, N >

A container that encapsulates fixed size arrays.

This class represents a container that encapsulates fixed size arrays.

It has the same semantics as a struct holding a C-style array T[N]. Unlike a C-style array, it doesn't decay to T* automatically.

The class combines the performance of a C-style array with the convenience of a standard container.

There is a special case for a zero-length array (N == 0). In that case, array.begin() == array.end(), which is some unique value.

Thread Safety

Not thread safe

Template Parameters
TThe array value type
NThe array size
See also

See Also std::vector

Member Typedef Documentation

◆ const_iterator

template<class T , std::size_t N>
typedef const T* boost::array< T, N >::const_iterator

Constant iterator to array, i.e. a pointer.

◆ const_reference

template<class T , std::size_t N>
typedef const T& boost::array< T, N >::const_reference

Constant reference to value type.

◆ const_reverse_iterator

template<class T , std::size_t N>
typedef std::reverse_iterator<const_iterator> boost::array< T, N >::const_reverse_iterator

Constant reverse array iterator - std::reverse_iterator<const_iterator>

◆ difference_type

template<class T , std::size_t N>
typedef std::ptrdiff_t boost::array< T, N >::difference_type

Type used to represent distance between iterators.

◆ iterator

template<class T , std::size_t N>
typedef T* boost::array< T, N >::iterator

Iterator to C-style array, i.e. a pointer.

◆ reference

template<class T , std::size_t N>
typedef T& boost::array< T, N >::reference

Reference to value type.

◆ reverse_iterator

template<class T , std::size_t N>
typedef std::reverse_iterator<iterator> boost::array< T, N >::reverse_iterator

Reverse array iterator - std::reverse_iterator<iterator>

◆ size_type

template<class T , std::size_t N>
typedef std::size_t boost::array< T, N >::size_type

Type used to represent array size.

◆ value_type

template<class T , std::size_t N>
typedef T boost::array< T, N >::value_type

The array value type.

Member Function Documentation

◆ assign()

template<class T , std::size_t N>
void boost::array< T, N >::assign ( const T &  value)

Assign one value to all elements.

This function assigns the same value to all arrays elements

Complexity

Linear

Note

This function is not available in std::array.

This function is a synonym for fill.

Returns
(none)
See also

See Also operator=, fill

◆ at() [1/2]

template<class T , std::size_t N>
reference boost::array< T, N >::at ( size_type  i)

Access specified element with bounds checking.

This function Returns a reference to the element at specified location i, with bounds checking.

If pos is not within the range of the container, an exception of type std::out_of_range is thrown.

Complexity

Constant

Preconditions

!(i < size())

Exception Safety

std::out_of_range if !(i < size()).

Returns
Reference to the requested element.
Parameters
iPosition of the element to return
See also

See Also operator[]

◆ at() [2/2]

template<class T , std::size_t N>
const_reference boost::array< T, N >::at ( size_type  i) const

Access specified element with bounds checking.

This function Returns a reference to the element at specified location i, with bounds checking.

If pos is not within the range of the container, an exception of type std::out_of_range is thrown.

This overload gets called when this is constant.

Complexity

Constant

Preconditions

!(i < size())

Exception Safety

std::out_of_range if !(i < size()).

Returns
Reference to the requested element.
Parameters
iPosition of the element to return
See also

See Also operator[]

◆ back() [1/2]

template<class T , std::size_t N>
reference boost::array< T, N >::back ( )

Access the last array element.

This function returns a reference to the last element in the container.

Calling front on an empty container is undefined.

Complexity

Constant

Note

c.back() is equivalent to *stdprev(c.end())

Preconditions

!(empty())

Returns
Reference to the last array element.
See also

See Also operator[], at, begin, end

◆ back() [2/2]

template<class T , std::size_t N>
constexpr const_reference boost::array< T, N >::back ( ) const
constexpr

Access the last array element.

This function returns a reference to the last element in the container.

Calling front on an empty container is undefined.

This overload gets called when this is constant.

Complexity

Constant

Note

c.back() is equivalent to *stdprev(c.end())

Preconditions

!(empty())

Returns
Reference to the last array element.
See also

See Also operator[], at, begin, end

◆ begin() [1/2]

template<class T , std::size_t N>
iterator boost::array< T, N >::begin ( )

Returns an iterator to the beginning.

This function returns an iterator to the first element of the array.

Complexity

Constant

Note

If the array is empty, the returned iterator will be equal to end()

Returns
Iterator to the first element of the array
See also

See Also end

◆ begin() [2/2]

template<class T , std::size_t N>
const_iterator boost::array< T, N >::begin ( ) const

Returns a constant iterator to the beginning.

This function returns a constant iterator to the first element of the array. This is the overload that gets called when this is constant.

Complexity

Constant

Note

If the array is empty, the returned iterator will be equal to end()

Returns
Iterator to the first element of the array
See also

See Also end

◆ c_array()

template<class T , std::size_t N>
T * boost::array< T, N >::c_array ( )

Direct access to the underlying array.

Returns pointer to the underlying array serving as element storage.

Complexity

Constant

Note

The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty.

When the container is empty, data() is not dereferenceable.

If size() is 0, data() may or may not return a null pointer.

This function is not available in std::array

Returns
Pointer to the underlying element storage

For non-empty containers, the returned pointer compares equal to the address of the first element.

See also

See Also front, back, size

◆ cbegin()

template<class T , std::size_t N>
const_iterator boost::array< T, N >::cbegin ( ) const

Returns a constant iterator to the beginning.

This function returns a constant iterator to the first element of the array.

This function is usually called to provide a constant iterator when this is not constant.

Complexity

Constant

Note

If the array is empty, the returned iterator will be equal to end()

@return Iterator to the first element of the array
See also

See Also end

◆ cend()

template<class T , std::size_t N>
const_iterator boost::array< T, N >::cend ( ) const

Returns a constant iterator to the end.

This function returns a constant iterator to the element following the last element of the array.

This function is usually called to provide a constant iterator when this is not constant.

Complexity

Constant

Note

If the array is empty, the returned iterator will be equal to end()

Returns
Iterator to the element following the last element of the array
See also

See Also cbegin

◆ crbegin()

template<class T , std::size_t N>
const_reverse_iterator boost::array< T, N >::crbegin ( ) const

Returns a reverse iterator to the beginning.

Returns a reverse iterator to the first element of the reversed array.

This reverse iterator corresponds to the last element of the non-reversed array.

This function is usually called to provide a constant iterator when this is not constant.

Complexity

Constant

Note

If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element of the reversed array
See also

See Also rend

◆ crend()

template<class T , std::size_t N>
const_reverse_iterator boost::array< T, N >::crend ( ) const

Returns a constant reverse iterator to the end.

Returns a reverse iterator to the element following the last element of the reversed array.

This iterator corresponds to the element preceding the first element of the non-reversed array.

This element acts as a placeholder. Attempting to access it results in undefined behavior.

This function is usually called to provide a constant iterator when this is not constant.

Complexity

Constant

Note

If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element of the reversed array
See also

See Also rend

◆ data() [1/2]

template<class T , std::size_t N>
T * boost::array< T, N >::data ( )

Direct access to the underlying array.

Returns pointer to the underlying array serving as element storage.

Complexity

Constant

Note

The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty.

When the container is empty, data() is not dereferenceable.

If size() is 0, data() may or may not return a null pointer.

Returns
Pointer to the underlying element storage

For non-empty containers, the returned pointer compares equal to the address of the first element.

See also

See Also front, back, size

◆ data() [2/2]

template<class T , std::size_t N>
const T * boost::array< T, N >::data ( ) const

Direct access to the underlying array.

Returns pointer to the underlying array serving as element storage.

This overload gets called when this is constant.

Complexity

Constant

Note

The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty.

When the container is empty, data() is not dereferenceable.

If size() is 0, data() may or may not return a null pointer.

Returns
Pointer to the underlying element storage

For non-empty containers, the returned pointer compares equal to the address of the first element.

See also

See Also front, back, size

◆ empty()

template<class T , std::size_t N>
static constexpr bool boost::array< T, N >::empty ( )
staticconstexpr

Checks whether the container is empty.

This function checks whether the container is empty

Complexity

Constant

Note

empty() is equivalent to begin() == end()

Returns
true if the container is empty, false otherwise
See also

See Also size, max_size

◆ end() [1/2]

template<class T , std::size_t N>
iterator boost::array< T, N >::end ( )

Returns an iterator to the end.

This function returns an iterator to the element following the last element of the array

Complexity

Constant

Note

If the array is empty, the returned iterator will be equal to end()

Returns
Iterator to the element following the last element of the array
See also

See Also begin

◆ end() [2/2]

template<class T , std::size_t N>
const_iterator boost::array< T, N >::end ( ) const

Returns a constant iterator to the end.

This function returns a constant iterator to the first element of the array.

This function overload gets called when this is constant.

Complexity

Constant

Note

If the array is empty, the returned iterator will be equal to end()

Returns
Iterator to the element following the last element of the array
See also

See Also begin

◆ fill()

template<class T , std::size_t N>
void boost::array< T, N >::fill ( const T &  value)

Assign one value to all elements.

This function assigns the same value to all arrays elements

Complexity

Linear

Note

This function is not available in std::array

Returns
(none)
See also

See Also operator=

◆ front() [1/2]

template<class T , std::size_t N>
reference boost::array< T, N >::front ( )

Access the first array element.

This function returns a reference to the first element in the container.

Calling front on an empty container is undefined.

Complexity

Constant

Note

c.front() is equivalent to *c.begin()

Preconditions

!(empty())

Returns
Reference to the first array element.
See also

See Also operator[], at, begin, end

◆ front() [2/2]

template<class T , std::size_t N>
constexpr const_reference boost::array< T, N >::front ( ) const
constexpr

Access the first array element.

This function returns a reference to the first element in the container.

Calling front on an empty container is undefined.

This overload gets called when this is constant.

Complexity

Constant

Note

c.front() is equivalent to *c.begin()

Preconditions

!(empty())

Returns
Reference to the first array element.
See also

See Also operator[], at, begin, end

◆ max_size()

template<class T , std::size_t N>
static constexpr size_type boost::array< T, N >::max_size ( )
staticconstexpr

Returns the maximum possible number of elements.

Returns the maximum number of elements the container is able to hold due to system or library implementation limitations

Complexity

Constant

Note

Because array<T, N> is a fixed-size container, the value returned by max_size() is equivalent to size()

Returns
Maximum number of elements
See also

See Also size, empty

◆ operator=()

template<class T , std::size_t N>
template<typename T2 >
array< T, N > & boost::array< T, N >::operator= ( const array< T2, N > &  rhs)

Overwrites element of the array with elements of another array.

This function overwrites every element of the this array with the corresponding elements of another array

Complexity

Linear

Returns
Pointer to this array
See also

See Also assign

◆ operator[]() [1/2]

template<class T , std::size_t N>
reference boost::array< T, N >::operator[] ( size_type  i)

Access specified element.

This function Returns a reference to the element at specified location i.

No bounds checking is performed.

Complexity

Constant

Preconditions

!(i < size())

Note

Unlike std::map::operator[], this operator never inserts a new element into the container.

Accessing a nonexistent element through this operator is undefined behavior.

Returns
Reference to the requested element.
Parameters
iPosition of the element to return
See also

See Also at

◆ operator[]() [2/2]

template<class T , std::size_t N>
const_reference boost::array< T, N >::operator[] ( size_type  i) const

Access specified element.

This function Returns a reference to the element at specified location i.

No bounds checking is performed.

This overload gets called when this is constant.

Complexity

Constant

Preconditions

!(i < size())

Note

Unlike std::map::operator[], this operator never inserts a new element into the container.

Accessing a nonexistent element through this operator is undefined behavior.

Returns
Reference to the requested element.
Parameters
iPosition of the element to return
See also

See Also at

◆ rangecheck()

template<class T , std::size_t N>
static constexpr bool boost::array< T, N >::rangecheck ( size_type  i)
staticconstexpr

Check range.

This function checks if i in the valid range for the array.

This function may be private because it is static.

Complexity

Constant

Exception Safety

Throws std::out_of_range if i is not in the valid range.

Note

This function is not available in std::array

Returns
True if i is in the valid range for the array
See also

See Also size, empty

◆ rbegin() [1/2]

template<class T , std::size_t N>
reverse_iterator boost::array< T, N >::rbegin ( )

Returns a reverse iterator to the beginning.

Returns a reverse iterator to the first element of the reversed array.

This reverse iterator corresponds to the last element of the non-reversed array.

Complexity

Constant

Note

If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element of the reversed array
See also

See Also rend

◆ rbegin() [2/2]

template<class T , std::size_t N>
const_reverse_iterator boost::array< T, N >::rbegin ( ) const

Returns a constant reverse iterator to the beginning.

Returns a reverse iterator to the first element of the reversed array.

This reverse iterator corresponds to the last element of the non-reversed array.

This function overload gets called when this is constant.

Complexity

Constant

Note

If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element of the reversed array
See also

See Also rend

◆ rend() [1/2]

template<class T , std::size_t N>
reverse_iterator boost::array< T, N >::rend ( )

Returns a reverse iterator to the end.

Returns a reverse iterator to the element following the last element of the reversed array.

This iterator corresponds to the element preceding the first element of the non-reversed array.

This element acts as a placeholder. Attempting to access it results in undefined behavior.

Complexity

Constant

Note

If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element of the reversed array
See also

See Also rend

◆ rend() [2/2]

template<class T , std::size_t N>
const_reverse_iterator boost::array< T, N >::rend ( ) const

Returns a constant reverse iterator to the end.

Returns a reverse iterator to the element following the last element of the reversed array.

This iterator corresponds to the element preceding the first element of the non-reversed array.

This element acts as a placeholder. Attempting to access it results in undefined behavior.

This function overload gets called when this is constant.

Complexity

Constant

Note

If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element of the reversed array
See also

See Also rend

◆ size()

template<class T , std::size_t N>
static constexpr size_type boost::array< T, N >::size ( )
staticconstexpr

Returns the number of elements.

This function returns the number of elements in the container.

Complexity

Constant

Note

size() is equivalent to std::distance(begin(), end())

Returns
The number of elements in the container
See also

See Also empty, max_size

◆ swap()

template<class T , std::size_t N>
void boost::array< T, N >::swap ( array< T, N > &  y)

Swaps the container contents.

Exchanges the contents of the container with those of other.

This function does not cause iterators and references to associate with the other container.

Complexity

Linear

Note

Because array<T, N> is not dynamically allocated, this operation has linear complexity.

Returns
(none)
Parameters
ycontainer to exchange the contents with
See also

See Also fill, std::swap

Member Data Documentation

◆ elems

template<class T , std::size_t N>
T boost::array< T, N >::elems[N]

Underlying fixed-size array of elements of type T.