atl/containers.hpp
Vector<T> and Optional<T>: the parts of std::vector and std::optional the SDK needs.
Functions
Section titled "Functions"inline constexpr NullOpt none{};Pass or return none for "no value".
Vector
Section titled "Vector"A growable array (like std::vector).
template <class T> class VectorVector() = default;An empty vector.
Vector(std::initializer_list<T> items);A vector holding the listed items.
Parameters
items(std::initializer_list<T>)
Vector(const Vector &o);A vector holding the listed items.
Parameters
o(const Vector<T> &)
Vector(Vector &&o) noexcept;A vector holding the listed items.
Parameters
o(Vector<T> &&)
Vector &operator=(Vector o) noexcept;Parameters
o(Vector<T>)
Returns Vector<T> &
size_t size() const;Number of elements.
Returns size_t
bool empty() const;True when there are no elements.
Returns bool
T &operator[](size_t i);The element at index i (unchecked).
Parameters
i(size_t)
Returns T &
const T &operator[](size_t i) const;The element at index i (unchecked).
Parameters
i(size_t)
Returns const T &
T *begin();Iteration over the elements.
Returns T *
T *end();Iteration over the elements.
Returns T *
const T *begin() const;Iteration over the elements.
Returns const T *
const T *end() const;Iteration over the elements.
Returns const T *
T &back();The last element. The vector must not be empty.
Returns T &
void reserve(size_t n);Makes room for at least n elements without reallocating.
Parameters
n(size_t)
template <class... A> T &emplace(A &&...args);Constructs a new element at the end from args and returns it.
Parameters
args(A &&...)
Returns T &
void push(const T &v);Appends a copy or moved value.
Parameters
v(const T &)
void push(T &&v);Appends a copy or moved value.
Parameters
v(T &&)
void pop();Removes the last element. The vector must not be empty.
void clear();Removes every element, keeping the capacity.
void swapRemove(size_t i);Removes element i in O(1) by moving the last element into its place. Changes the order of the remaining elements.
Parameters
i(size_t)
NullOpt
Section titled "NullOpt"Tag type for an empty Optional.
struct NullOptOptional
Section titled "Optional"Either holds a T or holds nothing (like std::optional).
template <class T> class OptionalOptional() = default;Empty.
Optional(NullOpt);Empty.
Optional(const T &v);Holds a copy or moved value.
Parameters
v(const T &)
Optional(T &&v);Holds a copy or moved value.
Parameters
v(T &&)
Optional(const Optional &o);Holds a copy or moved value.
Parameters
o(const Optional<T> &)
Optional(Optional &&o) noexcept;Holds a copy or moved value.
Parameters
o(Optional<T> &&)
Optional &operator=(Optional o);Parameters
o(Optional<T>)
Returns Optional<T> &
explicit operator bool() const;True when a value is held.
bool hasValue() const;Same as operator bool.
Returns bool
T &operator*();The held value. The Optional must not be empty.
Returns T &
const T &operator*() const;The held value. The Optional must not be empty.
Returns const T &
T *operator->();The held value. The Optional must not be empty.
Returns T *
const T *operator->() const;The held value. The Optional must not be empty.
Returns const T *
T valueOr(T fallback) const;The held value, or fallback when empty.
Parameters
fallback(T)
Returns T
void reset();Destroys the held value, leaving the Optional empty.