#include <muu/span.h>
template <typename T, size_t Extent = dynamic_extent, size_t Alignment = 0>
muu::span class

A non-owning view of contiguous elements.

Template parameters
T The span's element type.
Extent The number of elements represented by the span. Use muu::dynamic_extent for dynamically-sized spans.
Alignment The minimum byte alignment of the base data pointer held by the span. Must be a power-of-two and >= alignof(T). A value of 0 is accepted as alignof(T).

Public types

using const_pointer = std::add_pointer_t<std::add_const_t<T>>
A const pointer to the span's element type.
using const_reference = std::add_lvalue_reference_t<std::add_const_t<T>>
A const reference to the span's element type.
using difference_type = ptrdiff_t
std::ptrdiff_t
using element_type = T
The span's element type.
using iterator = pointer
A LegacyRandomAccessIterator for the elements in the span.
using pointer = std::add_pointer_t<T>
A pointer to the span's element type.
using reference = std::add_lvalue_reference_t<T>
A reference to the span's element type.
using reverse_iterator = std::reverse_iterator<iterator>
std::reverse_iterator<iterator>
using size_type = size_t
std::size_t
using value_type = std::remove_cv_t<T>
The span's base value type.

Public static variables

static size_t alignment constexpr
The minimum alignment of the base data pointer held by this span.
static size_t extent constexpr
The number of elements in the span, or muu::dynamic_extent.

Constructors, destructors, conversion operators

span() constexpr noexcept
Default constructor.
template <typename It>
span(It first, size_t count) explicit constexpr noexcept
Constructs a span from a contiguous iterator and an element count.
template <typename It, typename End>
span(It first, End last) explicit constexpr noexcept
Constructs a span from a pair of contiguous iterators.
template <typename U, size_t E, size_t A>
span(const span<U, E, A>& s) explicit constexpr noexcept
Constructs a span from another span.
template <size_t N>
span(element_type(&arr)[N]) constexpr noexcept
Constructs a span from an array.
template <typename U, size_t N>
span(std::array<U, N>& arr) constexpr noexcept
Constructs a span from an array.
template <typename U, size_t N>
span(const std::array<U, N>& arr) constexpr noexcept
Constructs a span from an array.
span(const span&) defaulted constexpr noexcept
Copy constructor.

Public functions

auto empty() const -> bool constexpr noexcept
Returns true if the span is empty (i.e. covers zero elements).
auto operator=(const span&) -> span& defaulted constexpr noexcept
Copy-assignment operator.
auto size() const -> size_t constexpr noexcept
Returns the number of elements covered by the span.
auto size_bytes() const -> size_t constexpr noexcept
Returns the total size of the elements covered by the span in bytes.

Elements

auto back() const -> reference constexpr noexcept
Returns a reference to the last element in the span.
auto data() const -> pointer constexpr noexcept
Returns a pointer to the first element in the span.
auto front() const -> reference constexpr noexcept
Returns a reference to the first element in the span.
auto operator[](size_t idx) const -> reference constexpr noexcept
Returns a reference to an arbitrary element in the span.

Iterators

auto begin() const -> iterator constexpr noexcept
Returns an iterator to the beginning of the span.
auto end() const -> iterator constexpr noexcept
Returns an iterator to end of the span.
auto rbegin() const -> reverse_iterator constexpr noexcept
Returns a reverse iterator to the beginning of the span.
auto rend() const -> reverse_iterator constexpr noexcept
Returns a reverse iterator to the end of the span.

Iterators (ADL)

auto begin(const span& s) -> iterator constexpr noexcept
Returns an iterator to the beginning of a span.
auto end(const span& s) -> iterator constexpr noexcept
Returns an iterator to end of a span.
auto rbegin(const span& s) -> reverse_iterator constexpr noexcept
Returns a reverse iterator to the beginning of a span.
auto rend(const span& s) -> reverse_iterator constexpr noexcept
Returns a reverse iterator to the end of a span.

Subspans

template <size_t Count>
auto first() const -> span<element_type, Count, Alignment> constexpr noexcept
Returns a subspan representing the first N elements of this span.
auto first(size_t count) const -> span<element_type, dynamic_extent, Alignment> constexpr noexcept
Returns a subspan representing the first N elements of this span.
template <size_t Count>
auto last() const -> span<element_type, Count> constexpr noexcept
Returns a subspan representing the last N elements of this span.
auto last(size_t count) const -> span<element_type> constexpr noexcept
Returns a subspan representing the last N elements of this span.
template <size_t Offset, size_t Count = dynamic_extent>
auto subspan() const -> auto constexpr noexcept
Returns an arbitrary subspan.
auto subspan(size_t offset, size_t count = dynamic_extent) const -> span<element_type> constexpr noexcept
Returns an arbitrary subspan.

Function documentation

template <typename T, size_t Extent, size_t Alignment>
muu::span::span() constexpr noexcept

Default constructor.

template <typename T, size_t Extent, size_t Alignment>
template <typename It>
muu::span::span(It first, size_t count) explicit constexpr noexcept

Constructs a span from a contiguous iterator and an element count.

template <typename T, size_t Extent, size_t Alignment>
template <typename It, typename End>
muu::span::span(It first, End last) explicit constexpr noexcept

Constructs a span from a pair of contiguous iterators.

template <typename T, size_t Extent, size_t Alignment>
template <typename U, size_t E, size_t A>
muu::span::span(const span<U, E, A>& s) explicit constexpr noexcept

Constructs a span from another span.