Sen API
Sen Libraries
Loading...
Searching...
No Matches
sen::Span< T > Class Template Reference

Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0122r7.pdf. More...

#include <span.h>

Public Types

using element_type = T
using value_type = std::remove_cv_t<T>
using index_type = std::size_t
using difference_type = ptrdiff_t
using pointer = T*
using reference = T&
using iterator = T*
using const_iterator = const T*
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>

Public Member Functions

 Span () noexcept=default
 ~Span () noexcept=default
template<typename U, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
constexpr Span (const Span< U > &other) noexcept
 Copy from a compatible Span.
constexpr Span (pointer ptr, index_type count) noexcept
 Builds a Span out of a pointer and an element count.
template<std::size_t n>
constexpr Span (std::array< value_type, n > &array) noexcept
 Builds a Span out of an array.
template<std::size_t n>
constexpr Span (const std::array< value_type, n > &array) noexcept
 Builds a Span out of an array.
template<typename U, std::size_t n, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
constexpr Span (std::array< U, n > &array) noexcept
 Builds a Span out of an array.
template<typename U, std::size_t n, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
constexpr Span (const std::array< U, n > &array) noexcept
 Builds a Span out of a const array.
constexpr Span (std::vector< value_type > &vector) noexcept
 Builds a Span out of a vector. NOLINTNEXTLINE(hicpp-explicit-conversions).
constexpr Span (const std::vector< value_type > &vector) noexcept
 Builds a Span out of a vector. NOLINTNEXTLINE(hicpp-explicit-conversions).
template<typename U, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
constexpr Span (std::vector< U > &vector) noexcept
 Builds a Span out of a compatible vector.
template<typename U, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
constexpr Span (const std::vector< U > &vector) noexcept
 Builds a Span out of a const compatible vector.
Span first (index_type count) const noexcept
 Returns a new span over the first count elements of *this.
Span last (index_type count) const noexcept
 Returns a new Span over the last count elements of *this.
Span subspan (index_type offset=0) const noexcept
 Returns a new Span over the elements of *this beginning at offset and extending for size() - offset elements.
Span subspan (index_type offset, index_type count) const noexcept
 Returns a new Span over the elements of *this beginning at offset and extending for count elements.
constexpr std::size_t size () const noexcept
 Number of elements covered by the Span.
constexpr bool empty () const noexcept
reference operator[] (index_type i) const noexcept
 Gets the element at index i. Complexity: constant.
constexpr pointer data () const noexcept
 Direct access to the underlying storage. Complexity: constant.
constexpr iterator begin () const noexcept
 Returns an iterator to the first element of the Span. If the vector is empty, the returned iterator will be equal to end(). Complexity: constant.
constexpr iterator end () const noexcept
 Iterator to the element following the last element. Complexity: constant. NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic).
constexpr const_iterator cbegin () const noexcept
 Returns a const iterator to the first element of the vector. If the Span is empty, the returned iterator will be equal to cend(). Complexity: constant.
constexpr const_iterator cend () const noexcept
 Constant iterator to the element following the last element. Complexity: constant. NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic).

Detailed Description

template<class T>
class sen::Span< T >

Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0122r7.pdf.

Warning
this class does not perform range checks.
Template Parameters
Telement type.

Member Typedef Documentation

◆ element_type

template<class T>
using sen::Span< T >::element_type = T

◆ value_type

template<class T>
using sen::Span< T >::value_type = std::remove_cv_t<T>

◆ index_type

template<class T>
using sen::Span< T >::index_type = std::size_t

◆ difference_type

template<class T>
using sen::Span< T >::difference_type = ptrdiff_t

◆ pointer

template<class T>
using sen::Span< T >::pointer = T*

◆ reference

template<class T>
using sen::Span< T >::reference = T&

◆ iterator

template<class T>
using sen::Span< T >::iterator = T*

◆ const_iterator

template<class T>
using sen::Span< T >::const_iterator = const T*

◆ reverse_iterator

template<class T>
using sen::Span< T >::reverse_iterator = std::reverse_iterator<iterator>

◆ const_reverse_iterator

template<class T>
using sen::Span< T >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Constructor & Destructor Documentation

◆ Span() [1/11]

template<class T>
sen::Span< T >::Span ( )
defaultnoexcept

◆ ~Span()

template<class T>
sen::Span< T >::~Span ( )
defaultnoexcept

◆ Span() [2/11]

template<class T>
template<typename U, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
sen::Span< T >::Span ( const Span< U > & other)
inlineconstexprnoexcept

Copy from a compatible Span.

◆ Span() [3/11]

template<class T>
sen::Span< T >::Span ( pointer ptr,
index_type count )
inlineconstexprnoexcept

Builds a Span out of a pointer and an element count.

Precondition
(ptr == nullptr && count == 0) || (ptr != nullptr && count >= 0)

◆ Span() [4/11]

template<class T>
template<std::size_t n>
sen::Span< T >::Span ( std::array< value_type, n > & array)
inlineconstexprnoexcept

Builds a Span out of an array.

◆ Span() [5/11]

template<class T>
template<std::size_t n>
sen::Span< T >::Span ( const std::array< value_type, n > & array)
inlineconstexprnoexcept

Builds a Span out of an array.

◆ Span() [6/11]

template<class T>
template<typename U, std::size_t n, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
sen::Span< T >::Span ( std::array< U, n > & array)
inlineconstexprnoexcept

Builds a Span out of an array.

◆ Span() [7/11]

template<class T>
template<typename U, std::size_t n, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
sen::Span< T >::Span ( const std::array< U, n > & array)
inlineconstexprnoexcept

Builds a Span out of a const array.

◆ Span() [8/11]

template<class T>
sen::Span< T >::Span ( std::vector< value_type > & vector)
inlineconstexprnoexcept

Builds a Span out of a vector. NOLINTNEXTLINE(hicpp-explicit-conversions).

◆ Span() [9/11]

template<class T>
sen::Span< T >::Span ( const std::vector< value_type > & vector)
inlineconstexprnoexcept

Builds a Span out of a vector. NOLINTNEXTLINE(hicpp-explicit-conversions).

◆ Span() [10/11]

template<class T>
template<typename U, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
sen::Span< T >::Span ( std::vector< U > & vector)
inlineconstexprnoexcept

Builds a Span out of a compatible vector.

◆ Span() [11/11]

template<class T>
template<typename U, std::enable_if_t< std::is_convertible_v< U *, T * >, int > = 0>
sen::Span< T >::Span ( const std::vector< U > & vector)
inlineconstexprnoexcept

Builds a Span out of a const compatible vector.

Member Function Documentation

◆ first()

template<typename T>
Span< T > sen::Span< T >::first ( index_type count) const
nodiscardnoexcept

Returns a new span over the first count elements of *this.

Precondition
count >= 0 && count <= size()

◆ last()

template<typename T>
Span< T > sen::Span< T >::last ( index_type count) const
nodiscardnoexcept

Returns a new Span over the last count elements of *this.

Precondition
count >= 0 && count <= size()

◆ subspan() [1/2]

template<typename T>
Span< T > sen::Span< T >::subspan ( index_type offset = 0) const
nodiscardnoexcept

Returns a new Span over the elements of *this beginning at offset and extending for size() - offset elements.

Precondition
offset >= 0 && offset <= size()

◆ subspan() [2/2]

template<typename T>
Span< T > sen::Span< T >::subspan ( index_type offset,
index_type count ) const
nodiscardnoexcept

Returns a new Span over the elements of *this beginning at offset and extending for count elements.

Precondition
offset >= 0 && count <= size() - offset

◆ size()

template<class T>
std::size_t sen::Span< T >::size ( ) const
inlinenodiscardconstexprnoexcept

Number of elements covered by the Span.

◆ empty()

template<class T>
bool sen::Span< T >::empty ( ) const
inlinenodiscardconstexprnoexcept
Returns
true if size() == 0, false otherwise.

◆ operator[]()

template<typename T>
Span< T >::reference sen::Span< T >::operator[] ( index_type i) const
nodiscardnoexcept

Gets the element at index i. Complexity: constant.

Precondition
i < size()
i >= 0
Warning
This function does not perform range checks. Please ensure that i is within valid limits.
Parameters
iindex of the element to fetch.
Returns
the value of the element at position i.

◆ data()

template<class T>
pointer sen::Span< T >::data ( ) const
inlinenodiscardconstexprnoexcept

Direct access to the underlying storage. Complexity: constant.

◆ begin()

template<class T>
iterator sen::Span< T >::begin ( ) const
inlinenodiscardconstexprnoexcept

Returns an iterator to the first element of the Span. If the vector is empty, the returned iterator will be equal to end(). Complexity: constant.

◆ end()

template<class T>
iterator sen::Span< T >::end ( ) const
inlinenodiscardconstexprnoexcept

Iterator to the element following the last element. Complexity: constant. NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic).

◆ cbegin()

template<class T>
const_iterator sen::Span< T >::cbegin ( ) const
inlinenodiscardconstexprnoexcept

Returns a const iterator to the first element of the vector. If the Span is empty, the returned iterator will be equal to cend(). Complexity: constant.

◆ cend()

template<class T>
const_iterator sen::Span< T >::cend ( ) const
inlinenodiscardconstexprnoexcept

Constant iterator to the element following the last element. Complexity: constant. NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic).


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