STL Containers: Array

array

Syntax

Defined in header <array>

Usage / Usability

std::array is a container that encapsulates fixed size arrays.

Element access

  • at – access specified element with bounds checking
  • operator[] – access specified element
  • front – access the first element
  • back – access the last element
  • data – direct access to the underlying array

Good to know

  • The struct combines the performance and accessibility of a C-style array with the benefits of a standard container, such as knowing its own size, supporting assignment, random access iterators, etc.
  • The effect of calling front() or back() on a zero-sized array is undefined.

void std::array:: fill( const T& value )

Assigns the given value value to all elements in the container.

 

std::get<X>(array) 

X must be an integer value in range [0, N). This is enforced at compile time as opposed to at() or operator[].

 

More information about array can be read on cppreference webpage.

Leave a comment

Your email address will not be published.