|
Celeritas 0.7+cf8d83d
|
Non-owning device-compatible 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. | |
| constexpr | Span (pointer d, std::size_t s) noexcept(ndebug_or_dyn) |
| Construct from data and size. | |
| template<class Iter > | |
| constexpr | Span (Iter first, Iter last) noexcept(ndebug_or_dyn) |
| Construct from two contiguous random-access iterators. | |
| template<std::size_t N, std::enable_if_t< N==Extent||Extent==dynamic_extent, bool > = true> | |
| constexpr | Span (element_type(&arr)[N]) noexcept |
| Construct from a C array. | |
| template<class U , std::size_t N, std::enable_if_t< detail::is_array_convertible_v< U, T > &&(N==Extent||Extent==dynamic_extent), bool > = true> | |
| constexpr | Span (Array< U, N > &arr) noexcept |
Construct implicitly from a mutable Array. | |
| template<class U , std::size_t N, std::enable_if_t< detail::is_array_convertible_v< U const, T > &&(N==Extent||Extent==dynamic_extent), bool > = true> | |
| constexpr | Span (Array< U, N > const &arr) noexcept |
Construct implicitly from a const Array. | |
| template<class U , std::size_t E2, std::enable_if_t< detail::is_array_convertible_v< U, T > &&(E2==Extent||Extent==dynamic_extent), bool > = true> | |
| constexpr | Span (Span< U, E2 > const &other) noexcept(ndebug_or_dyn) |
Construct implicitly from convertible span and extent. | |
| template<class U , std::size_t E2, std::enable_if_t< detail::is_array_convertible_v< U, T > &&Extent !=dynamic_extent &&E2==dynamic_extent, bool > = true> | |
| constexpr | Span (Span< U, E2 > const &other) noexcept(ndebug_or_dyn) |
| Require explicit conversion from dynamic to fixed extent. | |
| Span (Span const &)=default | |
| Span & | operator= (Span const &)=default |
| Span (Span &&)=default | |
| Span & | operator= (Span &&)=default |
Iterators | |
| constexpr iterator | begin () const |
| constexpr iterator | end () const |
Element access | |
| constexpr reference | operator[] (std::size_t i) const |
| constexpr reference | front () const |
| constexpr reference | back () const |
| constexpr pointer | data () const |
Observers | |
| constexpr bool | empty () const |
| constexpr std::size_t | size () const |
| constexpr std::size_t | size_bytes () const |
Subviews | |
| template<std::size_t Count> | |
| constexpr Span< T, Count > | first () const noexcept(ndebug) |
| constexpr Span< T, dynamic_extent > | first (std::size_t count) const noexcept(ndebug) |
| template<std::size_t Offset, std::size_t Count = dynamic_extent> | |
| constexpr Span< T, detail::subspan_extent(Extent, Offset, Count)> | subspan () const noexcept(ndebug) |
| constexpr Span< T, dynamic_extent > | subspan (std::size_t offset, std::size_t count=dynamic_extent) const noexcept(ndebug) |
| template<std::size_t Count> | |
| constexpr Span< T, Count > | last () const noexcept(ndebug) |
| constexpr Span< T, dynamic_extent > | last (std::size_t count) const noexcept(ndebug) |
Static Public Attributes | |
| static constexpr std::size_t | extent = Extent |
| Size (may be dynamic) | |
Non-owning device-compatible reference to a contiguous span of data.
| T | value type |
| Extent | fixed size; defaults to dynamic. |
A Span, like std::string_view, provides access to externally managed data. In Celeritas, this class is typically used as a return result from accessing a range of elements in a Collection.
This implementation is a nonconforming backport of the C++20 std::span. Improvements for standards compatibility are welcome as long as they retain the same behavior in device code. Important differences from the standard std::span include:
LdgValue<T> which causes element accessors and iterators to use value-semantics loads (optimized device loads) instead of references.make_span overloads for Array<T,N>, C arrays, and generic containers, plus to_array() convenience and a host-only operator<< using StreamableContainer.CELER_CONSTEXPR_FUNCTION for host/device compatibility.CELER_EXPECT to check for bounds validation in debug builds.CELERITAS_DEBUG is on.contiguous_iterator (first,last)operator[], front(), back() data(), size(), size_bytes(), empty() begin(), end() first<Count>(), first(count), last<Count>(), last(count) subspan<Offset,Count>() and subspan(offset,count) for compile-time and runtime subviewsmake_span(...) and to_array(...) Construct from two contiguous random-access iterators.
Extent is fixed-size, the SpanImpl will fire an assertion in debug mode if the size does not match.
|
inlineconstexprnoexcept |
Construct implicitly from a mutable Array.
Enabled only when N matches Extent exactly or Extent is dynamic_extent, so the conversion is always statically safe and can be implicit unconditionally.
|
inlineconstexprnoexcept |
Construct implicitly from a const Array.
Enabled only when N matches Extent exactly or Extent is dynamic_extent, so the conversion is always statically safe and can be implicit unconditionally.
|
inlineconstexprnoexcept |
Construct implicitly from convertible span and extent.
Note that the enable-if prevents LdgSpan->Span conversion. Conversions that may require a runtime size check (dynamic-extent source to fixed-extent destination) are made explicit to avoid accidental UB, matching std::span's behavior.
Implicit conversion for cases that are statically safe (e.g., fixed->dynamic, fixed->same-fixed, or just element-type qualification changes).
|
inlineexplicitconstexprnoexcept |
Require explicit conversion from dynamic to fixed extent.
Runtime size compatibility is checked in detail::SpanImpl.