Template Class array

Class Documentation

template<class T, std::size_t N>
class util::array

A container for continous fixed-size data.

constexpr const util::array<int, 3> numbers{1, 2, 3};

Public Types

using value_type = T
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using reference = value_type&
using const_reference = const value_type&
using pointer = value_type*
using const_pointer = const value_type*
using iterator = pointer
using const_iterator = const_pointer
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>

Public Functions

constexpr auto at(size_type pos) -> reference

Returns the element at the given position with boundary checking.

util::array<int, 3> numbers{1, 2, 3};
assert(numbers.at(0) == 1);

Parameters

pos – the requested element’s position

Throws

out_of_range – if pos >= size()

Returns

a reference to the requested element

constexpr auto at(size_type pos) const -> const_reference

See

auto array<T, N>::at(size_type pos) -> reference


constexpr auto operator[](size_type pos) -> reference

Returns the element at the given position without boundary checking.

util::array<int, 3> numbers{1, 2, 3};
assert(numbers[2] == 3);

Parameters

pos – the requested element’s position

Throws

util::assertion – if pos >= size() and UTIL_ASSERT defined

Returns

a reference to the requested element

constexpr auto operator[](size_type pos) const -> const_reference

See

auto array<T, N>::operator(size_type pos) -> reference

constexpr const util::array<int, 3> numbers{1, 2, 3};
assert(numbers[2] == 3);

constexpr auto front() -> reference

Returns the first element of the array.

util::array<int, 3> numbers{1, 2, 3};
assert(numbers.front() == 1);

Returns

the first element of the array

constexpr auto front() const -> const_reference

See

auto array<T, N>::front() -> reference

constexpr const util::array<int, 3> numbers{1, 2, 3};
assert(numbers.front() == 1);

constexpr auto back() -> reference

Returns the last element of the array.

util::array<int, 3> numbers{1, 2, 3};
assert(numbers.back() == 3);

Returns

the last element of the array

constexpr auto back() const -> const_reference

See

auto array<T, N>::back() -> reference

constexpr const util::array<int, 3> numbers{1, 2, 3};
assert(numbers.back() == 3);

constexpr auto data() noexcept -> pointer

Returns a direct pointer to the memory used internally by the array.

util::array<int, 3> numbers{1, 2, 3};
assert(*numbers.data() == 1);

Returns

a pointer to the first element in the array used internally by the array

constexpr auto data() const noexcept -> const_pointer

See

auto array<T, N>::data -> pointer

constexpr const util::array<int, 3> numbers{1, 2, 3};
assert(*numbers.data() == 1);

constexpr auto begin() noexcept -> iterator

Returns an iterator to the first element or the end() iterator if size() == 0.

util::array<int, 3> numbers{1, 2, 3};
assert(*numbers.begin() == 1);

Returns

an iterator to the first element

constexpr auto begin() const noexcept -> const_iterator
constexpr auto cbegin() const noexcept -> const_iterator
constexpr auto end() noexcept -> iterator
constexpr auto end() const noexcept -> const_iterator
constexpr auto cend() const noexcept -> const_iterator
constexpr auto rbegin() noexcept -> reverse_iterator
constexpr auto rbegin() const noexcept -> const_reverse_iterator
constexpr auto crbegin() const noexcept -> const_reverse_iterator
constexpr auto rend() noexcept -> reverse_iterator
constexpr auto rend() const noexcept -> const_reverse_iterator
constexpr auto crend() const noexcept -> const_reverse_iterator
constexpr auto empty() const noexcept -> bool
constexpr auto size() const noexcept -> size_type
constexpr auto max_size() const noexcept -> size_type
constexpr void fill(const T &value)
void swap(array &other)

Public Members

T elements[N]