Celeritas  0.5.0-86+4a8eea4
Public Member Functions | Static Public Attributes | List of all members
celeritas::Span< T, Extent > Class Template Reference

Non-owning reference to a contiguous span of data. More...

#include <Span.hh>

Public Types

Type aliases
using element_type = typename SpanTraitsT::element_type
 
using value_type = std::remove_cv_t< element_type >
 
using size_type = std::size_t
 
using pointer = typename SpanTraitsT::pointer
 
using const_pointer = typename SpanTraitsT::const_pointer
 
using reference = typename SpanTraitsT::reference
 
using const_reference = typename SpanTraitsT::const_reference
 
using iterator = typename SpanTraitsT::iterator
 
using const_iterator = typename SpanTraitsT::const_iterator
 

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.
 
 CELER_DEFAULT_COPY_MOVE (Span)
 
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, Countfirst () 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, Countlast () 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)
 

Detailed Description

template<class T, std::size_t Extent = dynamic_extent>
class celeritas::Span< T, Extent >

Non-owning reference to a contiguous span of data.

Template Parameters
Tvalue type
Extentfixed 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


The documentation for this class was generated from the following file: