Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::Span< Type > Struct Template Reference

View over a contiguous sequence of items (pointer + size in elements). More...

#include <Span.h>

Public Types

using SizeType = size_t
 
using VoidType = typename TypeTraits::SameConstnessAs< Type, void >::type
 

Public Member Functions

template<size_t N>
constexpr Span (Type(&_items)[N])
 
constexpr Span ()
 Builds an empty Span. More...
 
constexpr Span (Type *items, SizeType sizeInElements)
 Builds a Span from an array. More...
 
constexpr Span (Type &type)
 Builds a Span from a single object. More...
 
constexpr Span (std::initializer_list< Type > list)
 Span specialized constructor (mainly used for converting const char* to StringView) More...
 
 operator Span< const Type > () const
 Converts to a span with const qualified Type. More...
 
template<typename T >
Span< const T > reinterpret_as_array_of () const
 Reinterprets the current span as an array of the specified type. More...
 
constexpr const Type * begin () const
 Returns pointer to first element of the span. More...
 
constexpr const Type * end () const
 Returns pointer to one after the last element of the span. More...
 
constexpr const Type * data () const
 Returns pointer to first element of the span. More...
 
constexpr Type * begin ()
 Returns pointer to first element of the span. More...
 
constexpr Type * end ()
 Returns pointer to one after the last element of the span. More...
 
constexpr Type * data ()
 Returns pointer to first element of the span. More...
 
constexpr SizeType sizeInElements () const
 Size of Span in elements. More...
 
constexpr SizeType sizeInBytes () const
 Size of Span in bytes. More...
 
constexpr bool sliceStart (SizeType offsetInElements, Span &destination) const
 Creates another Span, starting at an offset in elements from current Span, until end. More...
 
constexpr bool sliceStartLength (SizeType offsetInElements, SizeType lengthInElements, Span &destination) const
 Creates another Span, starting at an offset in elements from current Span of specified length. More...
 
constexpr bool empty () const
 Check if Span is empty. More...
 
constexpr bool contains (const Type &type, SizeType *index=nullptr) const
 
Type & operator[] (SizeType idx)
 
const Type & operator[] (SizeType idx) const
 

Static Public Member Functions

template<typename T >
static Span< Type > reinterpret_object (T &value)
 Constructs a Span reinterpreting memory pointed by object of type T as a type Type More...
 
static Span< Type > reinterpret_bytes (VoidType *rawMemory, SizeType sizeInBytes)
 Construct a span reinterpreting raw memory (void* or const void*) to Type or const Type More...
 

Detailed Description

template<typename Type>
struct SC::Span< Type >

View over a contiguous sequence of items (pointer + size in elements).

Template Parameters
TypeAny type

Constructor & Destructor Documentation

◆ Span() [1/4]

template<typename Type >
constexpr SC::Span< Type >::Span ( )
inlineconstexpr

Builds an empty Span.

◆ Span() [2/4]

template<typename Type >
constexpr SC::Span< Type >::Span ( Type *  items,
SizeType  sizeInElements 
)
inlineconstexpr

Builds a Span from an array.

Parameters
itemspointer to the first member of the array
sizeInElementsnumber of elements in in the array

◆ Span() [3/4]

template<typename Type >
constexpr SC::Span< Type >::Span ( Type &  type)
inlineconstexpr

Builds a Span from a single object.

Parameters
typeA reference to a single object of type Type

◆ Span() [4/4]

template<typename Type >
constexpr SC::Span< Type >::Span ( std::initializer_list< Type >  list)
inlineconstexpr

Span specialized constructor (mainly used for converting const char* to StringView)

Parameters
listan initializer list of elements

Member Function Documentation

◆ begin() [1/2]

template<typename Type >
constexpr Type * SC::Span< Type >::begin ( )
inlineconstexpr

Returns pointer to first element of the span.

Returns
pointer to first element of the span

◆ begin() [2/2]

template<typename Type >
constexpr const Type * SC::Span< Type >::begin ( ) const
inlineconstexpr

Returns pointer to first element of the span.

Returns
pointer to first element of the span

◆ data() [1/2]

template<typename Type >
constexpr Type * SC::Span< Type >::data ( )
inlineconstexpr

Returns pointer to first element of the span.

Returns
pointer to first element of the span

◆ data() [2/2]

template<typename Type >
constexpr const Type * SC::Span< Type >::data ( ) const
inlineconstexpr

Returns pointer to first element of the span.

Returns
pointer to first element of the span

◆ empty()

template<typename Type >
constexpr bool SC::Span< Type >::empty ( ) const
inlineconstexpr

Check if Span is empty.

Returns
true if Span is empty

◆ end() [1/2]

template<typename Type >
constexpr Type * SC::Span< Type >::end ( )
inlineconstexpr

Returns pointer to one after the last element of the span.

Returns
Pointer to one after the last element of the span

◆ end() [2/2]

template<typename Type >
constexpr const Type * SC::Span< Type >::end ( ) const
inlineconstexpr

Returns pointer to one after the last element of the span.

Returns
Pointer to one after the last element of the span

◆ operator Span< const Type >()

template<typename Type >
SC::Span< Type >::operator Span< const Type > ( ) const
inline

Converts to a span with const qualified Type.

◆ reinterpret_as_array_of()

template<typename Type >
template<typename T >
Span< const T > SC::Span< Type >::reinterpret_as_array_of ( ) const
inline

Reinterprets the current span as an array of the specified type.

◆ reinterpret_bytes()

template<typename Type >
static Span< Type > SC::Span< Type >::reinterpret_bytes ( VoidType *  rawMemory,
SizeType  sizeInBytes 
)
inlinestatic

Construct a span reinterpreting raw memory (void* or const void*) to Type or const Type

Parameters
rawMemoryPointer to raw buffer of memory
sizeInBytesSize of the raw buffer in Bytes
Returns
The reinterpreted Span object

◆ reinterpret_object()

template<typename Type >
template<typename T >
static Span< Type > SC::Span< Type >::reinterpret_object ( T &  value)
inlinestatic

Constructs a Span reinterpreting memory pointed by object of type T as a type Type

Template Parameters
TType of object to be reinterpreted
Parameters
valueThe source object to be reinterpreted
Returns
The output converted Span object

◆ sizeInBytes()

template<typename Type >
constexpr SizeType SC::Span< Type >::sizeInBytes ( ) const
inlineconstexpr

Size of Span in bytes.

Returns
The number of bytes covering the entire Span

◆ sizeInElements()

template<typename Type >
constexpr SizeType SC::Span< Type >::sizeInElements ( ) const
inlineconstexpr

Size of Span in elements.

Returns
The number of elements of the Span

◆ sliceStart()

template<typename Type >
constexpr bool SC::Span< Type >::sliceStart ( SizeType  offsetInElements,
Span< Type > &  destination 
) const
inlineconstexpr

Creates another Span, starting at an offset in elements from current Span, until end.

Parameters
offsetInElementsOffset in current Span where destination Span will be starting
destinationReference to a Span that will hold the resulting computed span
Returns
  • true if destination has been written.
  • false if offsetInElements is bigger to than Span::size().

◆ sliceStartLength()

template<typename Type >
constexpr bool SC::Span< Type >::sliceStartLength ( SizeType  offsetInElements,
SizeType  lengthInElements,
Span< Type > &  destination 
) const
inlineconstexpr

Creates another Span, starting at an offset in elements from current Span of specified length.

Parameters
offsetInElementsOffset in current Span where destination Span will be starting
lengthInElementsNumber of elements wanted for destination Span
destinationReference to a Span that will hold the resulting computed span
Returns
  • true if destination has been written.
  • false if (offsetInElements + lengthInElements) is bigger to than Span::size().

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