legate::Span#

template<typename T>
class Span#

A simple span implementation used in Legate.

Should eventually be replaced with std::span once we bump up the C++ standard version to C++20

Public Functions

template<typename C, typename = std::enable_if_t<detail::is_container_v<C> && !std::is_same_v<C, std::initializer_list<T>>>>
constexpr Span(
C &container
)#

Construct a span from a container-like object.

This overload only participates in overload resolution if C satisfies ContainerLike. It must have a valid overload of std::data() and std::size() which refer to a contiguous buffer of data and its size respectively.

Parameters:

container – The container-like object.

constexpr Span(std::initializer_list<T> il)#

Construct a span from an initializer list of items directly.

This overload is relatively dangerous insofar that the span can very easily outlive the initializer list. It is generally only preferred to target this overload when taking a Span as a function argument where the ability to simply do foo({1, 2, 3, 4}) is preferred.

Parameters:

il – The initializer list.

constexpr Span(T *data, size_type size)#

Creates a span with an existing pointer and a size.

The caller must guarantee that the allocation is big enough (i.e., bigger than or equal to sizeof(T) * size) and that the allocation is alive while the span is alive.

Parameters:
  • data – Pointer to the data

  • size – Number of elements

size_type size() const#

Returns the number of elements.

Returns:

The number of elements

const_iterator begin() const#

Returns the pointer to the first element.

Returns:

Pointer to the first element

const_iterator end() const#

Returns the pointer to the end of allocation.

Returns:

Pointer to the end of allocation

iterator begin()#

Returns the pointer to the first element.

Returns:

Pointer to the first element

iterator end()#

Returns the pointer to the end of allocation.

Returns:

Pointer to the end of allocation

reverse_const_iterator rbegin() const#
Returns:

An iterator to the last element.

reverse_const_iterator rend() const#
Returns:

An iterator one past the first element.

reverse_iterator rbegin()#
Returns:

An iterator to the last element.

reverse_iterator rend()#
Returns:

An iterator one past the first element.

reference front() const#
Returns:

A reference to the first element in the span.

reference back() const#
Returns:

A reference to the last element in the span.

Span subspan(size_type off)#

Slices off the first off elements. Passing an off greater than the size will fail with an assertion failure.

Parameters:

off – Number of elements to skip

Returns:

A span for range [off, size())

const_pointer ptr() const#

Returns a const pointer to the data.

Returns:

Pointer to the data

pointer data() const#

Returns a pointer to the data.

Returns:

Pointer to the data.