vector.hpp

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

This class is a drop-in wrapper for std::vector, adding on bounds checking, both for the indexing operator and for the use of iterators (ensure that iterators do not outlive the version of vector for which it was created.) If EMP_NDEBUG is set then it reverts back to std::vector.

Todo:

Debug code: member functions that take iterators should also take emp iterators that verify whether those iterators are valid.

Note

Status: BETA

Functions

template<typename T, typename ...Ts>
std::ostream &operator<<(std::ostream &out, const vector<T, Ts...> &v)
template<typename T, typename ...Ts>
std::istream &operator>>(std::istream &is, vector<T, Ts...> &v)
template<typename T, typename ...Ts>
class vector : public std::vector<T, Ts...>
#include <vector.hpp>

Build a debug wrapper vector around std::vector.

Public Types

using iterator = iterator_wrapper<typename stdv_t::iterator>
using const_iterator = iterator_wrapper<typename stdv_t::const_iterator>
using reverse_iterator = iterator_wrapper<typename stdv_t::reverse_iterator>
using const_reverse_iterator = iterator_wrapper<typename stdv_t::const_reverse_iterator>
using value_type = T
using size_type = typename stdv_t::size_type
using reference = typename stdv_t::reference
using const_reference = typename stdv_t::const_reference

Public Functions

inline vector()
inline vector(const this_t &_in)
inline vector(size_t size)
inline vector(size_t size, const T &val)
inline vector(std::initializer_list<T> in_list)
inline vector(const stdv_t &in)
template<typename InputIt>
inline vector(InputIt first, InputIt last)
inline ~vector()
inline size_t size() const
inline iterator begin() noexcept
inline const_iterator begin() const noexcept
inline iterator end() noexcept
inline const_iterator end() const noexcept
inline const_iterator cbegin() const noexcept
inline const_iterator cend() const noexcept
inline reverse_iterator rbegin() noexcept
inline const_reverse_iterator rbegin() const noexcept
inline reverse_iterator rend() noexcept
inline const_reverse_iterator rend() const noexcept
inline const_reverse_iterator crbegin() const noexcept
inline const_reverse_iterator crend() const noexcept
inline void resize(size_t new_size)
inline void resize(size_t new_size, const T &val)
this_t &operator=(const this_t&) & = default
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
template<typename ...PB_Ts>
inline void push_back(PB_Ts&&... args)
inline void pop_back()
template<typename ...ARGS>
inline iterator insert(ARGS&&... args)
template<typename ...ARGS>
inline iterator erase(ARGS&&... args)
template<typename ...ARGS>
inline iterator emplace(ARGS&&... args)
template<typename ...ARGS>
inline void emplace_back(ARGS&&... args)

Public Members

int revision

Setup a revision number - iterators must match the revision of their vector.

Private Types

using this_t = vector<T, Ts...>
using stdv_t = std::vector<T, Ts...>

Private Static Attributes

static constexpr const size_t MAX_SIZE = 2000000001

Setup a threshold; if we try to make a vector bigger than MAX_SIZE, throw a warning.

template<typename ITERATOR_T>
struct iterator_wrapper : public ITERATOR_T
#include <vector.hpp>

Setup an iterator wrapper to make sure that they’re not used again after a vector changes.

Public Types

using this_t = iterator_wrapper<ITERATOR_T>
using wrapped_t = ITERATOR_T
using vec_t = vector<T, Ts...>

Public Functions

inline iterator_wrapper(const ITERATOR_T &_in, const vec_t *_v)
iterator_wrapper(const this_t&) = default
iterator_wrapper(this_t&&) = default
iterator_wrapper() = default
inline ~iterator_wrapper()
inline bool OK(bool begin_ok = true, bool end_ok = true, std::string op = "") 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 x)
inline this_t &operator--()
inline this_t operator--(int x)
inline auto operator+(int in)
inline auto operator-(int in)
inline auto operator-(const this_t &in)
inline this_t &operator+=(int in)
inline this_t &operator-=(int in)
inline auto &operator[](int offset)

Public Members

const vec_t *v_ptr

What vector and revision was this iterator created from?

int revision

Public Static Functions

static inline std::string &ErrorCode()
static inline std::string ErrorStart()
template<typename t>
class vector<bool>
#include <vector.hpp>

Build a specialized debug wrapper for vector<bool>

Public Types

using iterator = typename stdv_t::iterator
using const_iterator = typename stdv_t::const_iterator
using value_type = bool
using size_type = typename stdv_t::size_type
using reference = typename stdv_t::reference
using const_reference = typename stdv_t::const_reference

Public Functions

inline vector()
inline vector(const this_t &_in)
inline vector(size_t size)
inline vector(size_t size, bool val)
inline vector(std::initializer_list<bool> in_list)
inline vector(const stdv_t &in)
template<typename InputIt>
inline vector(InputIt first, InputIt last)
inline void resize(size_t new_size)
inline void resize(size_t new_size, bool val)
this_t &operator=(const this_t&) & = default
inline auto operator[](size_t pos) -> decltype(stdv_t::operator[](pos))
inline bool operator[](size_t pos) const
inline auto &back()
inline bool back() const
inline auto &front()
inline bool front() const
inline void pop_back()

Private Types

using this_t = vector<bool, Ts...>
using stdv_t = std::vector<bool, Ts...>

Private Static Attributes

static constexpr const size_t MAX_SIZE = 2000000001

Setup a threshold; if we try to make a vector bigger than MAX_SIZE, throw a warning.