-
Notifications
You must be signed in to change notification settings - Fork 0
Array
DryPerspective edited this page Sep 22, 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, allowing for easy stack arrays which do not decay, are passed around by reference easily, and which have a suite of helpful member 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 |
| begin(dp::array) cbegin(dp::array) |
Overloads of dp::begin for dp::array types |
| end(dp::array) cend(dp::array) |
Overloads of dp::end for dp::array types |
| rbegin(dp::array) crbegin(dp::array) |
Overloads of dp::rbegin for dp::array types |
| rend(dp::array) crend(dp::array) |
Overloads of dp::rend for dp::array types |
| data(dp::array) | Overloads of dp::data for dp::array types |
dp::array will work correctly with the general form of the range functions not listed here.
#include "cpp98/array.h"
#include "cpp98/iterator.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);
}
}