A drop-in wrapper for std::array; adds on bounds checking in debug mode. Status: RELEASE.

If EMP_NDEBUG is set, array is just an alias for std::array. Otherwise, every time an array is accessed, tests are done to make sure that the access is legal.


Add tests in array::front and array::back to ensure not empty.

Add tests for get.

template<typename ITERATOR_T, typename ARRAY_T>
struct array_iterator
#include <array.hpp>

Setup an iterator wrapper to check validity.

Public Types

using this_t = array_iterator<ITERATOR_T, ARRAY_T>
using array_t = ARRAY_T
using iterator_category = typename std::iterator_traits<ITERATOR_T>::iterator_category
using value_type = typename std::iterator_traits<ITERATOR_T>::value_type
using difference_type = typename std::iterator_traits<ITERATOR_T>::difference_type
using pointer = typename std::iterator_traits<ITERATOR_T>::pointer
using reference = typename std::iterator_traits<ITERATOR_T>::reference

Public Functions

inline array_iterator()
inline array_iterator(ITERATOR_T _in, const array_t *_v)
array_iterator(const this_t&) = default
array_iterator(this_t&&) = default
inline ~array_iterator()
inline bool OK(bool begin_ok = true, bool end_ok = true) const
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline operator ITERATOR_T()
inline operator const ITERATOR_T() const
inline auto &operator*()
inline const auto &operator*() const
inline auto operator->()
inline auto operator->() const
inline this_t &operator++()
inline this_t operator++(int)
inline this_t &operator--()
inline this_t operator--(int)
inline this_t operator+(int in)
inline this_t operator-(int in)
inline ptrdiff_t operator-(const this_t &in)
inline this_t &operator+=(int in)
inline this_t &operator-=(int in)
inline auto &operator[](int index)
inline const auto &operator[](int index) const

Public Members

const array_t *arr_ptr = {nullptr}
template<typename T, size_t NUM_ELEMENTS>
struct array
#include <array.hpp>

We are in debug mode, so array has the same interface as std::array, but with extra bounds checking. Using vector as our base since it has the right pieces and is dynamic.

Subclassed by WorldVector< Ptr< ORG > >

Public Types

using this_t = array<T, N>
using iterator = array_iterator<T*, this_t>
using const_iterator = array_iterator<const T*, this_t>
using reverse_iterator = array_iterator<std::reverse_iterator<iterator>, this_t>
using const_reverse_iterator = array_iterator<std::reverse_iterator<const_iterator>, this_t>
using value_type = T
using size_type = std::size_t
using reference = value_type&
using const_reference = const value_type&

Public Functions

int operator<=>(const array&) const = default
inline operator std::array<T, N>()
inline constexpr size_t size() const
inline auto &data()
inline const auto &data() const
inline iterator begin() noexcept
inline const_iterator begin() const noexcept
inline iterator end() noexcept
inline const_iterator end() const noexcept
inline T &operator[](size_t pos)
inline const T &operator[](size_t pos) const
inline T &back()
inline const T &back() const
inline T &front()
inline const T &front() const
inline void fill(const T &val)
inline void resize(size_t)
inline void resize(size_t, const T&)
template<typename ...PB_Ts>
inline void push_back(PB_Ts&&...)
inline void pop_back()
template<typename ...ARGS>
inline iterator insert(ARGS&&...)
template<typename ...ARGS>
inline iterator erase(ARGS&&...)
template<typename ...ARGS>
inline iterator emplace(ARGS&&...)
template<typename ...ARGS>
inline void emplace_back(ARGS&&...)
template<class Archive>
inline void serialize(Archive &ar)

Public Members

T _data[N ? N : 1]

Public Static Attributes

static constexpr size_t N = NUM_ELEMENTS
template<class T, size_t N>
struct tuple_size<array<T, N>> : public std::integral_constant<size_t, N>
#include <array.hpp>