Celeritas
0.5.0-56+6b053cd
|
Non-owning reference to a contiguous span of data. More...
#include <Span.hh>
Public Member Functions | |
constexpr | Span ()=default |
Construct with default null pointer and size zero. | |
CELER_FORCEINLINE_FUNCTION | Span (pointer d, size_type s) |
Construct from data and size. | |
template<class Iter > | |
CELER_FORCEINLINE_FUNCTION | Span (Iter first, Iter last) |
Construct from two contiguous random-access iterators. | |
template<std::size_t N> | |
CELER_CONSTEXPR_FUNCTION | Span (element_type(&arr)[N]) |
Construct from a C array. | |
template<class U , std::size_t N> | |
CELER_CONSTEXPR_FUNCTION | Span (Span< U, N > const &other) |
Construct from another span. | |
Span (Span const &) noexcept=default | |
Copy constructor (same template parameters) | |
Span & | operator= (Span const &) noexcept=default |
Assignment (same template parameters) | |
Iterators | |
CELER_CONSTEXPR_FUNCTION iterator | begin () const |
CELER_CONSTEXPR_FUNCTION iterator | end () const |
Element access | |
CELER_CONSTEXPR_FUNCTION reference | operator[] (size_type i) const |
CELER_CONSTEXPR_FUNCTION reference | front () const |
CELER_CONSTEXPR_FUNCTION reference | back () const |
CELER_CONSTEXPR_FUNCTION pointer | data () const |
Observers | |
CELER_CONSTEXPR_FUNCTION bool | empty () const |
CELER_CONSTEXPR_FUNCTION size_type | size () const |
CELER_CONSTEXPR_FUNCTION size_type | size_bytes () const |
Subviews | |
template<std::size_t Count> | |
CELER_FUNCTION Span< T, Count > | first () const |
CELER_FUNCTION Span< T, dynamic_extent > | first (std::size_t count) const |
template<std::size_t Offset, std::size_t Count = dynamic_extent> | |
CELER_FUNCTION Span< T, detail::subspan_extent(Extent, Offset, Count)> | subspan () const |
CELER_FUNCTION Span< T, dynamic_extent > | subspan (std::size_t offset, std::size_t count=dynamic_extent) const |
template<std::size_t Count> | |
CELER_FUNCTION Span< T, Count > | last () const |
CELER_FUNCTION Span< T, dynamic_extent > | last (std::size_t count) const |
Static Public Attributes | |
static constexpr std::size_t | extent = Extent |
Size (may be dynamic) | |
Non-owning reference to a contiguous span of data.
T | value type |
Extent | fixed size; defaults to dynamic. |
This Span class is a modified backport of the C++20 std::span
. In Celeritas, it is often used as a return value from accessing elements in a Collection
.
Like the celeritas::Array , this class isn't 100% compatible with the std::span
class (partly of course because language features are missing from C++14). The hope is that it will be complete and correct for the use cases needed by Celeritas (and, as a bonus, it will be device-compatible).
Notably, only a subset of the functions (those having to do with size) are constexpr
. This is to allow debug assertions.
Span can be instantiated with the special marker type LdgValue<T>
to optimize reading constant data on device memory. In that case, data returned by front
, back
, operator
[] and begin
/ end
iterator use value semantics instead of reference. data
still returns a pointer to the data and can be used to bypass using LdgIterator