array.hpp
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.
- Todo:
Add tests in array::front and array::back to ensure not empty.
Add tests for get.
-
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.
Public Types
-
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 reference = value_type&
-
using const_reference = const value_type&
Public Functions
- int operator (const array &) const =default
-
inline constexpr size_t size() const
-
inline auto &data()
-
inline const auto &data() const
-
inline const_iterator begin() const noexcept
-
inline const_iterator end() const noexcept
-
inline void resize(size_t)
-
inline void pop_back()
Public Static Attributes
-
static constexpr size_t N = NUM_ELEMENTS
-
using iterator = array_iterator<T*, this_t>
-
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 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)
-
inline ~array_iterator()
-
inline bool OK(bool begin_ok = true, bool end_ok = true) const
-
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 auto &operator[](int index)
-
inline const auto &operator[](int index) const
-
using this_t = array_iterator<ITERATOR_T, ARRAY_T>
-
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.
Public Types
-
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 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 void emplace_back(ARGS&&...)
-
template<class Archive>
inline void serialize(Archive &ar)
Public Static Attributes
-
static constexpr size_t N = NUM_ELEMENTS
-
using iterator = array_iterator<T*, this_t>