Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Public Member Functions | Private Attributes | Friends | List of all members
Span< C > Class Template Reference

A Span is an object that can refer to a contiguous sequence of objects. More...

#include <span.h>

Classes

struct  is_Span
 
struct  is_Span_int
 
struct  is_Span_int< Span< T > >
 

Public Member Functions

constexpr Span () noexcept
 
template<typename T , typename std::enable_if< std::is_convertible< T(*)[], C(*)[]>::value, int >::type = 0>
constexpr Span (T *begin, std::size_t size) noexcept
 Construct a span from a begin pointer and a size. More...
 
template<typename T , typename std::enable_if< std::is_convertible< T(*)[], C(*)[]>::value, int >::type = 0>
CONSTEXPR_IF_NOT_DEBUG Span (T *begin, T *end) noexcept
 Construct a span from a begin and end pointer. More...
 
template<typename O , typename std::enable_if< std::is_convertible< O(*)[], C(*)[]>::value, int >::type = 0>
constexpr Span (const Span< O > &other) noexcept
 Implicit conversion of spans between compatible types. More...
 
constexpr Span (const Span &) noexcept=default
 Default copy constructor. More...
 
Spanoperator= (const Span &other) noexcept=default
 Default assignment operator. More...
 
template<int N>
constexpr Span (C(&a)[N]) noexcept
 Construct a Span from an array. More...
 
template<typename V >
constexpr Span (V &other SPAN_ATTR_LIFETIMEBOUND, typename std::enable_if<!is_Span< V >::value &&std::is_convertible< typename std::remove_pointer< decltype(std::declval< V & >().data())>::type(*)[], C(*)[]>::value &&std::is_convertible< decltype(std::declval< V & >().size()), std::size_t >::value, std::nullptr_t >::type=nullptr)
 Construct a Span for objects with .data() and .size() (std::string, std::array, std::vector, ...). More...
 
template<typename V >
constexpr Span (const V &other SPAN_ATTR_LIFETIMEBOUND, typename std::enable_if<!is_Span< V >::value &&std::is_convertible< typename std::remove_pointer< decltype(std::declval< const V & >().data())>::type(*)[], C(*)[]>::value &&std::is_convertible< decltype(std::declval< const V & >().size()), std::size_t >::value, std::nullptr_t >::type=nullptr)
 
constexpr C * data () const noexcept
 
constexpr C * begin () const noexcept
 
constexpr C * end () const noexcept
 
CONSTEXPR_IF_NOT_DEBUG C & front () const noexcept
 
CONSTEXPR_IF_NOT_DEBUG C & back () const noexcept
 
constexpr std::size_t size () const noexcept
 
constexpr std::size_t size_bytes () const noexcept
 
constexpr bool empty () const noexcept
 
CONSTEXPR_IF_NOT_DEBUG C & operator[] (std::size_t pos) const noexcept
 
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan (std::size_t offset) const noexcept
 
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan (std::size_t offset, std::size_t count) const noexcept
 
CONSTEXPR_IF_NOT_DEBUG Span< C > first (std::size_t count) const noexcept
 
CONSTEXPR_IF_NOT_DEBUG Span< C > last (std::size_t count) const noexcept
 

Private Attributes

C * m_data
 
std::size_t m_size {0}
 

Friends

template<typename O >
class Span
 

Detailed Description

template<typename C>
class Span< C >

A Span is an object that can refer to a contiguous sequence of objects.

This file implements a subset of C++20's std::span. It can be considered temporary compatibility code until C++20 and is designed to be a self-contained abstraction without depending on other project files. For this reason, Clang lifetimebound is defined here instead of including <attributes.h>, which also defines it.

Things to be aware of when writing code that deals with Spans:

Definition at line 97 of file span.h.

Constructor & Destructor Documentation

◆ Span() [1/8]

template<typename C >
constexpr Span< C >::Span ( )
inlineconstexprnoexcept

Definition at line 111 of file span.h.

◆ Span() [2/8]

template<typename C >
template<typename T , typename std::enable_if< std::is_convertible< T(*)[], C(*)[]>::value, int >::type = 0>
constexpr Span< C >::Span ( T begin,
std::size_t  size 
)
inlineconstexprnoexcept

Construct a span from a begin pointer and a size.

This implements a subset of the iterator-based std::span constructor in C++20, which is hard to implement without std::address_of.

Definition at line 119 of file span.h.

◆ Span() [3/8]

template<typename C >
template<typename T , typename std::enable_if< std::is_convertible< T(*)[], C(*)[]>::value, int >::type = 0>
CONSTEXPR_IF_NOT_DEBUG Span< C >::Span ( T begin,
T end 
)
inlinenoexcept

Construct a span from a begin and end pointer.

This implements a subset of the iterator-based std::span constructor in C++20, which is hard to implement without std::address_of.

Definition at line 127 of file span.h.

Here is the call graph for this function:

◆ Span() [4/8]

template<typename C >
template<typename O , typename std::enable_if< std::is_convertible< O(*)[], C(*)[]>::value, int >::type = 0>
constexpr Span< C >::Span ( const Span< O > &  other)
inlineconstexprnoexcept

Implicit conversion of spans between compatible types.

Specifically, if a pointer to an array of type O can be implicitly converted to a pointer to an array of type C, then permit implicit conversion of Span<O> to Span<C>. This matches the behavior of the corresponding C++20 std::span constructor.

For example this means that a Span<T> can be converted into a Span<const T>.

Definition at line 141 of file span.h.

◆ Span() [5/8]

template<typename C >
constexpr Span< C >::Span ( const Span< C > &  )
constexprdefaultnoexcept

Default copy constructor.

◆ Span() [6/8]

template<typename C >
template<int N>
constexpr Span< C >::Span ( C(&)  a[N])
inlineconstexprnoexcept

Construct a Span from an array.

This matches the corresponding C++20 std::span constructor.

Definition at line 151 of file span.h.

◆ Span() [7/8]

template<typename C >
template<typename V >
constexpr Span< C >::Span ( V &other  SPAN_ATTR_LIFETIMEBOUND,
typename std::enable_if<!is_Span< V >::value &&std::is_convertible< typename std::remove_pointer< decltype(std::declval< V & >().data())>::type(*)[], C(*)[]>::value &&std::is_convertible< decltype(std::declval< V & >().size()), std::size_t >::value  ,
std::nullptr_t  ,
::type  = nullptr 
)
inlineconstexpr

Construct a Span for objects with .data() and .size() (std::string, std::array, std::vector, ...).

This implements a subset of the functionality provided by the C++20 std::span range-based constructor.

To prevent surprises, only Spans for constant value types are supported when passing in temporaries. Note that this restriction does not exist when converting arrays or other Spans (see above).

Definition at line 161 of file span.h.

◆ Span() [8/8]

template<typename C >
template<typename V >
constexpr Span< C >::Span ( const V &other  SPAN_ATTR_LIFETIMEBOUND,
typename std::enable_if<!is_Span< V >::value &&std::is_convertible< typename std::remove_pointer< decltype(std::declval< const V & >().data())>::type(*)[], C(*)[]>::value &&std::is_convertible< decltype(std::declval< const V & >().size()), std::size_t >::value  ,
std::nullptr_t  ,
::type  = nullptr 
)
inlineconstexpr

Definition at line 168 of file span.h.

Member Function Documentation

◆ back()

template<typename C >
CONSTEXPR_IF_NOT_DEBUG C & Span< C >::back ( ) const
inlinenoexcept

Definition at line 182 of file span.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

template<typename C >
constexpr C * Span< C >::begin ( ) const
inlineconstexprnoexcept

Definition at line 175 of file span.h.

Here is the caller graph for this function:

◆ data()

template<typename C >
constexpr C * Span< C >::data ( ) const
inlineconstexprnoexcept

Definition at line 174 of file span.h.

Here is the caller graph for this function:

◆ empty()

template<typename C >
constexpr bool Span< C >::empty ( ) const
inlineconstexprnoexcept

Definition at line 189 of file span.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

template<typename C >
constexpr C * Span< C >::end ( ) const
inlineconstexprnoexcept

Definition at line 176 of file span.h.

Here is the caller graph for this function:

◆ first()

template<typename C >
CONSTEXPR_IF_NOT_DEBUG Span< C > Span< C >::first ( std::size_t  count) const
inlinenoexcept

Definition at line 205 of file span.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ front()

template<typename C >
CONSTEXPR_IF_NOT_DEBUG C & Span< C >::front ( ) const
inlinenoexcept

Definition at line 177 of file span.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ last()

template<typename C >
CONSTEXPR_IF_NOT_DEBUG Span< C > Span< C >::last ( std::size_t  count) const
inlinenoexcept

Definition at line 210 of file span.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

template<typename C >
Span & Span< C >::operator= ( const Span< C > &  other)
defaultnoexcept

Default assignment operator.

◆ operator[]()

template<typename C >
CONSTEXPR_IF_NOT_DEBUG C & Span< C >::operator[] ( std::size_t  pos) const
inlinenoexcept

Definition at line 190 of file span.h.

Here is the call graph for this function:

◆ size()

template<typename C >
constexpr std::size_t Span< C >::size ( ) const
inlineconstexprnoexcept

Definition at line 187 of file span.h.

◆ size_bytes()

template<typename C >
constexpr std::size_t Span< C >::size_bytes ( ) const
inlineconstexprnoexcept

Definition at line 188 of file span.h.

◆ subspan() [1/2]

template<typename C >
CONSTEXPR_IF_NOT_DEBUG Span< C > Span< C >::subspan ( std::size_t  offset) const
inlinenoexcept

Definition at line 195 of file span.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subspan() [2/2]

template<typename C >
CONSTEXPR_IF_NOT_DEBUG Span< C > Span< C >::subspan ( std::size_t  offset,
std::size_t  count 
) const
inlinenoexcept

Definition at line 200 of file span.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ Span

template<typename C >
template<typename O >
friend class Span
friend

Definition at line 216 of file span.h.

Member Data Documentation

◆ m_data

template<typename C >
C* Span< C >::m_data
private

Definition at line 99 of file span.h.

◆ m_size

template<typename C >
std::size_t Span< C >::m_size {0}
private

Definition at line 100 of file span.h.


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