Backport
bpstd::span< T, Extent > Class Template Reference

This class is a non-owning view of a contiguous piece of memory. More...

#include <span.hpp>

Public Types

using element_type = T
 
using value_type = remove_cv_t< T >
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using pointer = element_type *
 
using const_pointer = const element_type *
 
using reference = element_type &
 
using const_reference = const element_type &
 
using iterator = detail::proxy_iterator< T *, detail::span_storage_type< T, Extent > >
 
using reverse_iterator = std::reverse_iterator< iterator >
 

Public Member Functions

template<std::size_t UExtent = Extent, typename = enable_if_t<detail::is_allowed_extent_conversion<0,UExtent>::value>>
constexpr span () noexcept
 Default-constructs a span. More...
 
template<typename It , typename End , enable_if_t<(Extent==bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr span (It it, End end) noexcept
 Constructs a span from an iterator range. More...
 
template<typename It , typename End , enable_if_t<(Extent !=bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr span (It it, End end) noexcept
 
template<std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr span (element_type(&arr)[N]) noexcept
 Constructs a span from an array reference. More...
 
template<typename U , std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr span (const span< U, N > &s) noexcept
 Constructs a span from a different span. More...
 
constexpr span (const span &other) noexcept=default
 Constructs a span by copying other. More...
 
BPSTD_CPP14_CONSTEXPR span & operator= (const span &other) noexcept=default
 Assigns a span from other. More...
 
constexpr reference front () const noexcept
 Gets a reference to the front element of this span. More...
 
constexpr reference back () const noexcept
 Gets a reference to the back element of this span. More...
 
constexpr reference operator[] (size_type idx) const noexcept
 Gets a reference to the element at idx. More...
 
constexpr pointer data () const noexcept
 Gets a pointer to the start of the data. More...
 
constexpr size_type size () const noexcept
 Gets the number of elements in this span. More...
 
constexpr size_type size_bytes () const noexcept
 Gets the number of bytes in this span. More...
 
constexpr bool empty () const noexcept
 Queries whether this span is empty. More...
 
template<std::size_t Count>
constexpr span< element_type, Count > first () const
 Creates a subspan from the first Count elements. More...
 
constexpr span< element_type > first (size_t count) const
 Creates a subspan from the first count elements. More...
 
template<std::size_t Count>
constexpr span< element_type, Count > last () const
 Creates a subspan from the last Count elements. More...
 
constexpr span< element_type > last (size_t count) const
 Creates a subspan from the last count elements. More...
 
template<std::size_t Offset, std::size_t Count = dynamic_extent>
constexpr span< element_type, detail::compute_subspan_size< Extent, Offset, Count >::value > subspan () const
 Creates a subspan that is Count elements long, Offset from the start of this span. More...
 
constexpr span< element_type > subspan (std::size_t offset, std::size_t count=dynamic_extent) const
 Creates a subspan that is count elements long, offset from the start of this span. More...
 
constexpr iterator begin () const noexcept
 
constexpr iterator end () const noexcept
 
constexpr reverse_iterator rbegin () const noexcept
 
constexpr reverse_iterator rend () const noexcept
 
template<typename It , bpstd::enable_if_t<(Extent==bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > >
constexpr BPSTD_INLINE_VISIBILITY span (It it, size_type count) noexcept
 
template<typename It , typename End , bpstd::enable_if_t<(Extent==bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > >
constexpr BPSTD_INLINE_VISIBILITY span (It it, End end) noexcept
 
template<std::size_t N, typename >
constexpr BPSTD_INLINE_VISIBILITY span (element_type(&arr)[N]) noexcept
 
template<typename U , std::size_t N, typename >
constexpr BPSTD_INLINE_VISIBILITY span (std::array< U, N > &arr) noexcept
 
template<typename U , std::size_t N, typename >
constexpr BPSTD_INLINE_VISIBILITY span (const std::array< U, N > &arr) noexcept
 
template<typename U , std::size_t N, typename >
constexpr BPSTD_INLINE_VISIBILITY span (const span< U, N > &s) noexcept
 
template<std::size_t Count>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< typename bpstd::span< T, Extent >::element_type, Count > first () const
 
template<std::size_t Count>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< typename bpstd::span< T, Extent >::element_type, Count > last () const
 
template<std::size_t Offset, std::size_t Count>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< typename bpstd::span< T, Extent >::element_type, bpstd::detail::compute_subspan_size< Extent, Offset, Count >::value > subspan () const
 
template<typename It , enable_if_t<(Extent==bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr span (It it, size_type count) noexcept
 Constructs a span from an iterator it and the count. More...
 
template<typename It , enable_if_t<(Extent !=bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr span (It it, size_type count) noexcept
 Constructs a span from an iterator it and the count. More...
 
template<typename U , std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr span (std::array< U, N > &arr) noexcept
 Constructs a span from a reference to a std::array. More...
 
template<typename U , std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr span (const std::array< U, N > &arr) noexcept
 Constructs a span from a reference to a std::array. More...
 

Static Public Attributes

static constexpr BPSTD_CPP17_INLINE std::size_t extent = Extent
 

Detailed Description

template<typename T, std::size_t Extent = dynamic_extent>
class bpstd::span< T, Extent >

This class is a non-owning view of a contiguous piece of memory.

This type describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero. A span can either have a static extent, in which case the number of elements in the sequence is known and encoded in the type, or a dynamic extent, in which case the size is known at runtime.

Template Parameters
Tthe underlying type of the span
Extentthe extent (size) of the span

Definition at line 182 of file span.hpp.

Constructor & Destructor Documentation

◆ span() [1/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t UExtent = Extent, typename = enable_if_t<detail::is_allowed_extent_conversion<0,UExtent>::value>>
constexpr bpstd::span< T, Extent >::span ( )
constexprnoexcept

Default-constructs a span.

This constructor only participates in overload resolution if the span either is size 0, or has a dynamic extent

◆ span() [2/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename It , enable_if_t<(Extent==bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr bpstd::span< T, Extent >::span ( It  it,
size_type  count 
)
constexprnoexcept

Constructs a span from an iterator it and the count.

This constructor only participates in overload resolution if the following criteria are met:

  • Extent is dynamic_extent
  • to_address(it) is convertible to T*

This constructor is explicit if Extent != dynamic_extent

Parameters
itthe iterator
countthe number of entries in the sequence

◆ span() [3/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename It , enable_if_t<(Extent !=bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr bpstd::span< T, Extent >::span ( It  it,
size_type  count 
)
explicitconstexprnoexcept

Constructs a span from an iterator it and the count.

This constructor only participates in overload resolution if the following criteria are met:

  • Extent is dynamic_extent
  • to_address(it) is convertible to T*

This constructor is explicit if Extent != dynamic_extent

Parameters
itthe iterator
countthe number of entries in the sequence

◆ span() [4/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename It , typename End , enable_if_t<(Extent==bpstd::dynamic_extent) &&bpstd::detail::is_iter_convertible< It, T >::value, int > = 0>
constexpr bpstd::span< T, Extent >::span ( It  it,
End  end 
)
constexprnoexcept

Constructs a span from an iterator range.

This constructor only participates in overload resolution if the following criteria are met:

  • Extent is dynamic_extent
  • to_address(it) is convertible to T*
Parameters
itthe iterator
endthe end iterator

◆ span() [5/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr bpstd::span< T, Extent >::span ( element_type(&)  arr[N])
constexprnoexcept

Constructs a span from an array reference.

This constructor only participates in overload resolution if any of the following criteria are met:

  • Extent is dynamic_extent
  • N is the same as Extent
Parameters
arrthe array reference

◆ span() [6/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr bpstd::span< T, Extent >::span ( std::array< U, N > &  arr)
constexprnoexcept

Constructs a span from a reference to a std::array.

This constructor only participates in overload resolution if the following criteria are met:

  • Extent is dynamic_extent or N is the same as Extent
  • U is at most a cv-qualification difference from T
Parameters
arrthe array reference

◆ span() [7/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr bpstd::span< T, Extent >::span ( const std::array< U, N > &  arr)
constexprnoexcept

Constructs a span from a reference to a std::array.

This constructor only participates in overload resolution if the following criteria are met:

  • Extent is dynamic_extent or N is the same as Extent
  • U is at most a cv-qualification difference from T
Parameters
arrthe array reference

◆ span() [8/9]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , std::size_t N, typename = enable_if_t<detail::is_allowed_extent_conversion<N,Extent>::value>>
constexpr bpstd::span< T, Extent >::span ( const span< U, N > &  s)
constexprnoexcept

Constructs a span from a different span.

This constructor only participates in overload resolution if the following criteria are met:

  • Extent is dynamic_extent or N is the same as Extent
  • U is at most a cv-qualification difference from T
Parameters
sthe span

◆ span() [9/9]

template<typename T , std::size_t Extent = dynamic_extent>
constexpr bpstd::span< T, Extent >::span ( const span< T, Extent > &  other)
constexprdefaultnoexcept

Constructs a span by copying other.

Parameters
otherthe other span to copy

Member Function Documentation

◆ back()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< T, Extent >::reference bpstd::span< T, Extent >::back
inlineconstexprnoexcept

Gets a reference to the back element of this span.

Precondition
empty() is false
Returns
reference to back element

Definition at line 602 of file span.hpp.

◆ data()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< T, Extent >::pointer bpstd::span< T, Extent >::data
inlineconstexprnoexcept

Gets a pointer to the start of the data.

Returns
pointer to the data

Definition at line 620 of file span.hpp.

◆ empty()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bool bpstd::span< T, Extent >::empty
inlineconstexprnoexcept

Queries whether this span is empty.

Returns
true if this span is empty

Definition at line 650 of file span.hpp.

◆ first() [1/2]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t Count>
constexpr span<element_type, Count> bpstd::span< T, Extent >::first ( ) const
constexpr

Creates a subspan from the first Count elements.

Precondition
A program is ill-formed if Count > Extent
Template Parameters
Countthe number of elements to create in the subspan
Returns
the first Count elements

◆ first() [2/2]

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< typename bpstd::span< T, Extent >::element_type > bpstd::span< T, Extent >::first ( size_t  count) const
inlineconstexpr

Creates a subspan from the first count elements.

Precondition
It is undefined behavior if count > size()
Parameters
countthe number of elements to create in the subspan
Returns
the first count elements

Definition at line 678 of file span.hpp.

◆ front()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< T, Extent >::reference bpstd::span< T, Extent >::front
inlineconstexprnoexcept

Gets a reference to the front element of this span.

Precondition
empty() is false
Returns
reference to front element

Definition at line 593 of file span.hpp.

◆ last() [1/2]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t Count>
constexpr span<element_type, Count> bpstd::span< T, Extent >::last ( ) const
constexpr

Creates a subspan from the last Count elements.

Precondition
A program is ill-formed if Count > Extent
Template Parameters
Countthe number of elements to create in the subspan
Returns
the last Count elements

◆ last() [2/2]

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< typename bpstd::span< T, Extent >::element_type > bpstd::span< T, Extent >::last ( size_t  count) const
inlineconstexpr

Creates a subspan from the last count elements.

Precondition
It is undefined behavior if count > size()
Parameters
countthe number of elements to create in the subspan
Returns
the last count elements

Definition at line 704 of file span.hpp.

◆ operator=()

template<typename T , std::size_t Extent = dynamic_extent>
BPSTD_CPP14_CONSTEXPR span& bpstd::span< T, Extent >::operator= ( const span< T, Extent > &  other)
defaultnoexcept

Assigns a span from other.

Parameters
otherthe other span to copy
Returns
reference to this

◆ operator[]()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< T, Extent >::reference bpstd::span< T, Extent >::operator[] ( size_type  idx) const
inlineconstexprnoexcept

Gets a reference to the element at idx.

Precondition
idx is less than size()
Parameters
idxthe index
Returns
reference to the element at idx

Definition at line 611 of file span.hpp.

◆ size()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< T, Extent >::size_type bpstd::span< T, Extent >::size
inlineconstexprnoexcept

Gets the number of elements in this span.

Returns
the number of elements in this span

Definition at line 633 of file span.hpp.

◆ size_bytes()

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< T, Extent >::size_type bpstd::span< T, Extent >::size_bytes
inlineconstexprnoexcept

Gets the number of bytes in this span.

Returns
the number of bytes in this span

Definition at line 642 of file span.hpp.

◆ subspan() [1/2]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t Offset, std::size_t Count = dynamic_extent>
constexpr span<element_type, detail::compute_subspan_size<Extent,Offset,Count>::value> bpstd::span< T, Extent >::subspan ( ) const
constexpr

Creates a subspan that is Count elements long, Offset from the start of this span.

Template Parameters
Offsetthe amount to offset the span by
Countthe number of elements to create in the subspan
Returns
the created subspan

◆ subspan() [2/2]

template<typename T , std::size_t Extent>
constexpr BPSTD_INLINE_VISIBILITY bpstd::span< typename bpstd::span< T, Extent >::element_type > bpstd::span< T, Extent >::subspan ( std::size_t  offset,
std::size_t  count = dynamic_extent 
) const
inlineconstexpr

Creates a subspan that is count elements long, offset from the start of this span.

Parameters
offsetthe amount to offset the span by
countthe number of elements to create in the subspan
Returns
the created subspan

Definition at line 733 of file span.hpp.


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