cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
cppcore::TSpan< T > Class Template Reference

This class implements a view onto array data. More...

#include <TSpan.h>

Public Types

using Iterator = const T*
 The iterator type.

Public Member Functions

 TSpan ()=default
 The default class constructor.
 TSpan (const T *ptr, size_t size)
 The class constructor with the pointer and the size of the array.
 ~TSpan ()=default
 The class destructor.
const T * data () const
 Will return the data pointer showing to the first entry.
size_t size () const
 Will return the number of items in the view.
bool empty () const
 Will return true, if the span view is empty.
Iterator begin ()
 Will return the begin iterator.
Iterator end ()
 Will return the end iterator.
T operator[] (size_t index)
 Will return the item at the given index.
const T operator[] (size_t index) const
 Will return the item at the given index.

Detailed Description

template<class T>
class cppcore::TSpan< T >

This class implements a view onto array data.

Definition at line 38 of file TSpan.h.

Member Typedef Documentation

◆ Iterator

template<class T>
using cppcore::TSpan< T >::Iterator = const T*

The iterator type.

Definition at line 41 of file TSpan.h.

Constructor & Destructor Documentation

◆ TSpan() [1/2]

template<class T>
cppcore::TSpan< T >::TSpan ( )
default

The default class constructor.

References size().

◆ TSpan() [2/2]

template<class T>
cppcore::TSpan< T >::TSpan ( const T * ptr,
size_t size )
inline

The class constructor with the pointer and the size of the array.

Parameters
[in]ptrThe pointer to the array.
[in]sizeThe array size.

Definition at line 90 of file TSpan.h.

References size().

◆ ~TSpan()

template<class T>
cppcore::TSpan< T >::~TSpan ( )
default

The class destructor.

Member Function Documentation

◆ begin()

template<class T>
TSpan< T >::Iterator cppcore::TSpan< T >::begin ( )
inline

Will return the begin iterator.

Returns
The begin iterator.

Definition at line 110 of file TSpan.h.

◆ data()

template<class T>
const T * cppcore::TSpan< T >::data ( ) const
inline

Will return the data pointer showing to the first entry.

Returns
The array pointer or nullptr, if no array was set.

Definition at line 95 of file TSpan.h.

◆ empty()

template<class T>
bool cppcore::TSpan< T >::empty ( ) const
inline

Will return true, if the span view is empty.

Returns
true,

Definition at line 105 of file TSpan.h.

◆ end()

template<class T>
TSpan< T >::Iterator cppcore::TSpan< T >::end ( )
inline

Will return the end iterator.

Returns
The end iterator.

Definition at line 115 of file TSpan.h.

◆ operator[]() [1/2]

template<class T>
T cppcore::TSpan< T >::operator[] ( size_t index)
inline

Will return the item at the given index.

If the index is out of range, the maximum value of T will be returned.

Parameters
indexThe item index.
Returns
The item at the given index or the maximum value of T, if the index is out of range.

Definition at line 120 of file TSpan.h.

◆ operator[]() [2/2]

template<class T>
const T cppcore::TSpan< T >::operator[] ( size_t index) const
inline

Will return the item at the given index.

If the index is out of range, the maximum value of T will be returned.

Parameters
indexThe item index.
Returns
The item at the given index or the maximum value of T, if the index is out of range.

Definition at line 128 of file TSpan.h.

◆ size()

template<class T>
size_t cppcore::TSpan< T >::size ( ) const
inline

Will return the number of items in the view.

Returns
The number of items.

Definition at line 100 of file TSpan.h.

Referenced by TSpan(), and TSpan().


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