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
Function Description begin Returns an iterator pointing to the first element in the array. Useful for traversing the array from the beginning. end Returns an iterator pointing to the position after the last element in the array. Used to mark the end of traversal. rbegin Returns a reverse iterator pointing to the last element in the array. Traverses the array in reverse order. rend Returns a reverse iterator pointing to the position before the first element in reverse traversal. cbegin Returns a constant iterator to the first element. The elements cannot be modified through this iterator. cend Returns a constant iterator to the position after the last element. Useful for read-only traversal. crbegin Returns a constant reverse iterator to the last element. Ensures read-only reverse traversal. crend Returns a constant reverse iterator to the position before the first element in reverse order. Ensures read-only access.
Capacity
Function Description size Returns the number of elements in the array. Always returns the fixed size specified at compile time. max_size Returns the maximum number of elements the array can hold. Equivalent to size()
. empty Checks whether the array is empty. Always returns false
for std::array
since its size is fixed.
Element Access
Function Description at Accesses the element at a specified index with bounds checking. Throws an exception if the index is out of range. front Returns a reference to the first element in the array. back Returns a reference to the last element in the array. data Returns a pointer to the underlying data of the array.
Modifiers
Function Description fill Fills all elements in the array with the specified value. swap Swaps the contents of the array with another array of the same type and size.