absl::AnySpan

A type-erased, non-owning view over a random-access sequence.

Synopsis

Declared in <absl/types/any_span.h>

template<typename T>
class AnySpan;

Description

Like absl::Span, an AnySpan refers to elements owned elsewhere, but it can wrap any container, array, or view of a compatible element type and can apply a transform to each element on access. It must not outlive the data, transform, or container it refers to.

Types

NameDescription
const_iterator Random-access iterator over the const elements of an AnySpan.
iterator Random-access iterator over the elements of an AnySpan.

Type Aliases

NameDescription
absl_internal_is_view Tag marking AnySpan as a view type.
const_pointer A pointer to a const element.
const_reference A reference to a const element.
const_reverse_iterator A reverse iterator over const elements.
difference_type A signed type used for iterator differences.
element_type The element type, including any const-qualification.
pointer A pointer to an element.
reference A reference to an element.
reverse_iterator A reverse iterator over the elements.
size_type An unsigned type used for sizes and indices.
value_type The element type with const removed.

Member Functions

NameDescription
AnySpan [constructor]Constructors
at Returns a reference to the element at index, with bounds checking.
back Returns a reference to the last element; the span must not be empty.
begin Returns an iterator to the first element.
cbegin Returns a const iterator to the first element.
cend Returns a const iterator just past the last element.
crbegin Returns a const reverse iterator to the last element.
crend Returns a const reverse iterator just before the first element.
empty Reports whether this span is empty.
end Returns an iterator just past the last element.
first Returns a span containing the first len elements.
front Returns a reference to the first element; the span must not be empty.
last Returns a span containing the last len elements.
operator[] Returns a reference to the element at index.
rbegin Returns a reverse iterator to the last element.
rend Returns a reverse iterator just before the first element.
size Returns the number of elements in this span.
subspan Returns a subspan starting at pos and spanning len elements.

Static Data Members

NameDescription
npos Sentinel size value meaning "until the end of the span".

Friends

NameDescription
absl::operator!=Compares two spans for inequality.
absl::operator==Compares two spans for element-wise equality.
absl::operator!=Compares two const spans for inequality.
absl::operator==Compares two const spans for element-wise equality.
absl::AnySpanA type-erased, non-owning view over a random-access sequence.
absl::AbslHashValueHashes the span's elements for use with absl::Hash.

Non-Member Functions

NameDescription
MakeAnySpanConstructs an AnySpan from a non-view container or array.
MakeAnySpanConstructs an AnySpan from a view container or array.
MakeAnySpanConstructs an AnySpan from a pointer and a size.
MakeConstAnySpanConstructs a const AnySpan from a non-view container or array.
MakeConstAnySpanConstructs a const AnySpan from a pointer and a size.
MakeConstAnySpanConstructs a const AnySpan from a view container or array.
MakeConstDerefAnySpanConstructs a const AnySpan dereferencing a view container of pointers.
MakeConstDerefAnySpanConstructs a const AnySpan dereferencing a non-view container of pointers.
MakeDerefAnySpanConstructs an AnySpan that dereferences a view container of pointers.
MakeDerefAnySpanConstructs an AnySpan that dereferences a non-view container of pointers.