Bitcoin Core  21.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 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 friend bool operator== (const Span &a, const Span &b) noexcept
 
constexpr friend bool operator!= (const Span &a, const Span &b) noexcept
 
constexpr friend bool operator< (const Span &a, const Span &b) noexcept
 
constexpr friend bool operator<= (const Span &a, const Span &b) noexcept
 
constexpr friend bool operator> (const Span &a, const Span &b) noexcept
 
constexpr friend 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 92 of file span.h.

Constructor & Destructor Documentation

◆ Span() [1/8]

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

Definition at line 106 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 114 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 122 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 136 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 146 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 156 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 163 of file span.h.

Member Function Documentation

◆ back()

template<typename C >
CONSTEXPR_IF_NOT_DEBUG C& Span< C >::back ( ) 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:

◆ begin()

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

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

Here is the call graph for this function:

◆ end()

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

Definition at line 171 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 199 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 172 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 204 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.

◆ operator[]()

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

Definition at line 184 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 182 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 189 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 194 of file span.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator!=

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

Definition at line 211 of file span.h.

◆ operator<

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

Definition at line 212 of file span.h.

◆ operator<=

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

Definition at line 213 of file span.h.

◆ operator==

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

Definition at line 210 of file span.h.

◆ operator>

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

Definition at line 214 of file span.h.

◆ operator>=

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

Definition at line 215 of file span.h.

◆ Span

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

Definition at line 217 of file span.h.

Member Data Documentation

◆ m_data

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

Definition at line 94 of file span.h.

◆ m_size

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

Definition at line 95 of file span.h.


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