Bitcoin Core  0.20.99
P2P Digital Currency
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>

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 , typename std::enable_if<(std::is_const< C >::value||std::is_lvalue_reference< 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, int >::type = 0>
constexpr Span (V &&v) noexcept
 Construct a Span for objects with .data() and .size() (std::string, std::array, std::vector, ...). More...
 
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 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
 

Friends

template<typename O >
class Span
 
constexpr bool operator== (const Span &a, const Span &b) noexcept
 
constexpr bool operator!= (const Span &a, const Span &b) noexcept
 
constexpr bool operator< (const Span &a, const Span &b) noexcept
 
constexpr bool operator<= (const Span &a, const Span &b) noexcept
 
constexpr bool operator> (const Span &a, const Span &b) noexcept
 
constexpr bool operator>= (const Span &a, const Span &b) noexcept
 

Detailed Description

template<typename C>
class Span< C >

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

It implements a subset of C++20's std::span.

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

Definition at line 82 of file span.h.

Constructor & Destructor Documentation

◆ Span() [1/7]

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

Definition at line 88 of file span.h.

Here is the caller graph for this function:

◆ Span() [2/7]

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 
)
inlinenoexcept

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 96 of file span.h.

◆ Span() [3/7]

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 104 of file span.h.

Here is the call graph for this function:

◆ Span() [4/7]

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)
inlinenoexcept

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 118 of file span.h.

Here is the call graph for this function:

◆ Span() [5/7]

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

Default copy constructor.

◆ Span() [6/7]

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

Construct a Span from an array.

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

Definition at line 128 of file span.h.

Here is the call graph for this function:

◆ Span() [7/7]

template<typename C>
template<typename V , typename std::enable_if<(std::is_const< C >::value||std::is_lvalue_reference< 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, int >::type = 0>
constexpr Span< C >::Span ( V &&  v)
inlinenoexcept

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 138 of file span.h.

Member Function Documentation

◆ back()

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

Definition at line 148 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
inlinenoexcept

Definition at line 141 of file span.h.

Here is the caller graph for this function:

◆ data()

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

Definition at line 140 of file span.h.

Here is the caller graph for this function:

◆ empty()

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

Definition at line 154 of file span.h.

Here is the call graph for this function:

◆ end()

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

Definition at line 142 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 170 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 143 of file span.h.

Here is the call 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 175 of file span.h.

Here is the call graph for this function:

◆ operator=()

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

Default assignment operator.

Here is the caller graph for this function:

◆ operator[]()

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

Definition at line 155 of file span.h.

Here is the call graph for this function:

◆ size()

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

Definition at line 153 of file span.h.

Here is the caller graph for this function:

◆ subspan() [1/2]

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

Definition at line 160 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 165 of file span.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator!=

template<typename C>
constexpr bool operator!= ( const Span< C > &  a,
const Span< C > &  b 
)
friend

Definition at line 182 of file span.h.

◆ operator<

template<typename C>
constexpr bool operator< ( const Span< C > &  a,
const Span< C > &  b 
)
friend

Definition at line 183 of file span.h.

◆ operator<=

template<typename C>
constexpr bool operator<= ( const Span< C > &  a,
const Span< C > &  b 
)
friend

Definition at line 184 of file span.h.

◆ operator==

template<typename C>
constexpr bool operator== ( const Span< C > &  a,
const Span< C > &  b 
)
friend

Definition at line 181 of file span.h.

◆ operator>

template<typename C>
constexpr bool operator> ( const Span< C > &  a,
const Span< C > &  b 
)
friend

Definition at line 185 of file span.h.

◆ operator>=

template<typename C>
constexpr bool operator>= ( const Span< C > &  a,
const Span< C > &  b 
)
friend

Definition at line 186 of file span.h.

◆ Span

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

Definition at line 188 of file span.h.

Member Data Documentation

◆ m_data

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

Definition at line 84 of file span.h.

◆ m_size

template<typename C>
std::size_t Span< C >::m_size
private

Definition at line 85 of file span.h.


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