Skip to content
DryPerspective edited this page Sep 19, 2023 · 3 revisions

A C++98 version of std::array, from the <array> header. It follows the same template pattern, typedefs, and interface as its standard counterpart.

Functions

at Array access with bounds checking
operator[] Array access without bounds checking
front Accesses first element
back Accesses last element
data Direct access to underlying array
begin
cbegin
Creates an iterator to the beginning of the array
end
cend
Creates an iterator to the end of the array
rbegin
crbegin
Creates a reverse iterator to the beginning
rend
crend
Creates a reverse iterator to the end
empty Checks whether the array is empty
size Returns the number of elements
max_size Returns the maximum possible number of elements
fill Fills the array with the specified value
swap Swaps the contents of two arrays
operator==
operator!=
operator<
operator<=
operator>
operator>=
Lexicographically compares the contents of two arrays

Sample Code

#include "cpp98/array.h"

void PrintCopySize(dp::array<int,5> arr){  //Copying without array decay
    Print(arr.size());                     //Size available quickly and easily
}

template<typename T, std::size_t N>
void PrintArrayContents(const dp::array<T,N>& arr){
    typedef typename dp::array<T,N>::const_iterator Iter;
    for(Iter it = arr.cbegin(); it != arr.cend(); ++it){
        Print(*it);
    }
}

Clone this wiki locally