C++ array Library

The C++ Standard Library’s <array> header provides a static array implementation, offering a safer and more versatile alternative to raw C-style arrays. It includes a variety of member functions that simplify array manipulation while maintaining type safety and ease of use.


Iterators

FunctionDescription
beginReturns an iterator pointing to the first element in the array. Useful for traversing the array from the beginning.
endReturns an iterator pointing to the position after the last element in the array. Used to mark the end of traversal.
rbeginReturns a reverse iterator pointing to the last element in the array. Traverses the array in reverse order.
rendReturns a reverse iterator pointing to the position before the first element in reverse traversal.
cbeginReturns a constant iterator to the first element. The elements cannot be modified through this iterator.
cendReturns a constant iterator to the position after the last element. Useful for read-only traversal.
crbeginReturns a constant reverse iterator to the last element. Ensures read-only reverse traversal.
crendReturns a constant reverse iterator to the position before the first element in reverse order. Ensures read-only access.

Capacity

FunctionDescription
sizeReturns the number of elements in the array. Always returns the fixed size specified at compile time.
max_sizeReturns the maximum number of elements the array can hold. Equivalent to size().
emptyChecks whether the array is empty. Always returns false for std::array since its size is fixed.

Element Access

FunctionDescription
atAccesses the element at a specified index with bounds checking. Throws an exception if the index is out of range.
frontReturns a reference to the first element in the array.
backReturns a reference to the last element in the array.
dataReturns a pointer to the underlying data of the array.

Modifiers

FunctionDescription
fillFills all elements in the array with the specified value.
swapSwaps the contents of the array with another array of the same type and size.