OGLplus  (0.59.0) a C++ wrapper for rendering APIs

eagine::memory::basic_span< ValueType, Pointer, SizeType > Class Template Reference

Non-owning view of a contiguous range of memory with ValueType elements. More...

#include <eagine/memory/span.hpp>

Public Types

using value_type = ValueType
 The element value type.
 
using size_type = SizeType
 The element count type.
 
using address_type = basic_address< std::is_const_v< ValueType > >
 The memory address type.
 
using pointer = Pointer
 The pointer type.
 
using iterator = Pointer
 The iterator type.
 
using const_iterator = Pointer
 The const iterator type.
 
using reverse_iterator = std::reverse_iterator< iterator >
 The reverse iterator type.
 

Public Member Functions

constexpr basic_span (pointer addr, size_type len) noexcept
 Construction from pointer and length.
 
constexpr basic_span (address_type addr, size_type len) noexcept
 Construction from memory address and length.
 
constexpr basic_span (pointer b, pointer e) noexcept
 Construction from a pair of pointers.
 
constexpr basic_span (address_type ba, address_type be) noexcept
 Construction from a pair of memory addresses.
 
constexpr basic_span () noexcept=default
 Default constructor. Constructs an empty span. More...
 
constexpr basic_span (const basic_span &) noexcept=default
 Copy constructor.
 
constexpr basic_span (basic_span &&) noexcept=default
 Move constructor.
 
auto operator= (const basic_span &) noexcept -> basic_span &=default
 Copy assignment operator.
 
auto operator= (basic_span &&) noexcept -> basic_span &=default
 Move assignment operator.
 
template<typename T , typename P , typename S , typename = enable_if_convertible<T, P, S>, typename = enable_if_different<T, P, S>>
constexpr basic_span (basic_span< T, P, S > that) noexcept
 Converting copy constructor from span of compatible elements.
 
template<typename T , typename P , typename S , typename = enable_if_convertible<T, P, S>, typename = enable_if_different<T, P, S>>
auto operator= (basic_span< T, P, S > that) noexcept -> auto &
 Converting copy assignment from span of compatible elements.
 
auto reset () noexcept -> auto &
 Resets this span. More...
 
auto reset (pointer addr, size_type length) noexcept -> auto &
 Resets this span with a new pointer and length.
 
auto reset (address_type addr, size_type length) noexcept -> auto &
 Resets this span with a new memory address and length.
 
auto reset (pointer b, pointer e) noexcept -> auto &
 Resets this span with a pair or pointers.
 
constexpr operator bool () const noexcept
 Indicates that the span is not empty. More...
 
constexpr auto is_empty () const noexcept -> bool
 Indicates that the span is empty. More...
 
constexpr auto empty () const noexcept -> bool
 Indicates that the span is empty. More...
 
constexpr auto is_zero_terminated () const noexcept -> bool
 Indicates that the span is terminated with value T(0) if applicable.
 
constexpr auto size () const noexcept -> size_type
 Returns the number of elements in the span. More...
 
constexpr auto data () const noexcept -> pointer
 Returns a pointer to the start of the span. More...
 
constexpr auto begin () const noexcept -> iterator
 Returns an interator to the start of the span.
 
constexpr auto end () const noexcept -> iterator
 Returns a iterator past the end of the span.
 
constexpr auto rbegin () const noexcept
 Returns a reverse interator to the end of the span.
 
constexpr auto rend () const noexcept
 Returns a reverse interator past the begin of the span.
 
constexpr auto addr () const noexcept -> address_type
 Returns the memory address of the start of the span.
 
constexpr auto begin_addr () const noexcept -> address_type
 Returns the memory address of the start of the span.
 
constexpr auto end_addr () const noexcept -> address_type
 Returns the memory address past the end of the span.
 
template<typename X >
auto is_aligned_as () const noexcept -> bool
 Checks if the start of the span is aligned as the alignment of X.
 
auto encloses (const_address a) const noexcept -> bool
 Indicates if this span encloses the specified address. More...
 
template<typename Ts , typename Ps , typename Ss >
auto contains (basic_span< Ts, Ps, Ss > that) const noexcept -> bool
 Indicates if this span encloses another span. More...
 
template<typename Ts , typename Ps , typename Ss >
auto overlaps (const basic_span< Ts, Ps, Ss > &that) const noexcept -> bool
 Indicates if this span overlaps with another span. More...
 
constexpr auto ref (size_type index) const noexcept -> std::add_const_t< value_type > &
 Returns a const reference to value at the specified index. More...
 
auto ref (size_type index) noexcept -> value_type &
 Returns a reference to value at the specified index. More...
 
auto front () const noexcept -> const value_type &
 Returns a const reference to value at the front of the span. More...
 
auto front () noexcept -> value_type &
 Returns a reference to value at the front of the span. More...
 
auto back () const noexcept -> const value_type &
 Returns a const reference to value at the back of the span. More...
 
auto back () noexcept -> value_type &
 Returns a const reference to value at the back of the span. More...
 
template<typename Int >
constexpr auto element (Int index) const noexcept -> std::enable_if_t< std::is_integral_v< Int >, std::add_const_t< value_type > & >
 Returns a const reference to value at the specified index. More...
 
template<typename Int >
auto element (Int index) noexcept -> std::enable_if_t< std::is_integral_v< Int >, value_type & >
 Returns a reference to value at the specified index. More...
 
template<typename Int >
auto operator[] (Int index) noexcept -> std::enable_if_t< std::is_integral_v< Int >, value_type & >
 Array subscript operator. More...
 
template<typename Int >
constexpr auto operator[] (Int index) const noexcept -> std::enable_if_t< std::is_integral_v< Int >, std::add_const_t< value_type > & >
 Array subscript operator. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T , typename P , typename S , typename Output >
static auto list_to_stream (Output &out, memory::basic_span< T, P, S > s) -> Output &
 Helper function for pretty-printing spans as lists into output streams. More...
 
template<typename Input , typename T , typename P , typename S >
static auto read_from_stream (Input &in, memory::basic_span< T, P, S > s) -> auto &
 Helper function for raw-reading spans from output streams. More...
 
template<typename Output , typename T , typename P , typename S >
static auto write_to_stream (Output &out, memory::basic_span< T, P, S > s) -> auto &
 Helper function for raw-reading spans into output streams. More...
 
template<typename T , typename P , typename S >
static auto operator<< (std::ostream &out, memory::basic_span< T, P, S > s) -> std::enable_if_t<!std::is_same_v< std::remove_const_t< T >, char >, std::ostream & >
 Operator for printing generic element spans into output streams. More...
 
template<typename T , typename P , typename S >
static auto operator<< (std::ostream &out, memory::basic_span< T, P, S > s) -> std::enable_if_t< std::is_same_v< std::remove_const_t< T >, char >, std::ostream & >
 Operator for printing spans of string characters into output streams. More...
 
template<typename T , typename P , typename S >
static auto make_span_getter (span_size_t &i, memory::basic_span< T, P, S > spn)
 Makes a callable that returns consecutive span elements starting at i. More...
 
template<typename T , typename P , typename S , typename Transform >
static auto make_span_getter (span_size_t &i, memory::basic_span< T, P, S > spn, Transform transform)
 Makes a callable getting consecutive, transformed span elements starting at i. More...
 
template<typename T , typename P , typename S >
static auto make_span_putter (span_size_t &i, memory::basic_span< T, P, S > spn)
 Makes a callable setting consecutive elements of a span starting at i. More...
 
template<typename T , typename P , typename S , typename Transform >
static auto make_span_putter (span_size_t &i, memory::basic_span< T, P, S > spn, Transform transform)
 Makes a callable setting consecutive elements of a span starting at i. More...
 

Detailed Description

template<typename ValueType, typename Pointer = ValueType*, typename SizeType = span_size_t>
class eagine::memory::basic_span< ValueType, Pointer, SizeType >

Non-owning view of a contiguous range of memory with ValueType elements.

Template Parameters
ValueTypethe type of elements assumed in the covered memory range.
Pointerthe pointer type used to point to the start of the span.
SizeTypethe integer type used to count the elements in the span.
See also
basic_block
basic_split_span

This template is similar to std::span but allows to specify other pointer types besides ValueType*, for example basic_offset_ptr, etc. and to specify the size type.

Constructor & Destructor Documentation

◆ basic_span()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
constexpr eagine::memory::basic_span< ValueType, Pointer, SizeType >::basic_span ( )
constexprdefaultnoexcept

Default constructor. Constructs an empty span.

Postcondition
is_empty()
size() == 0

Referenced by eagine::memory::basic_span< const gl_types::ubyte_type >::reset().

Member Function Documentation

◆ back() [1/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::back ( ) const -> const value_type&
inlinenoexcept

Returns a const reference to value at the back of the span.

See also
front
Precondition
!is_empty()

◆ back() [2/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::back ( ) -> value_type&
inlinenoexcept

Returns a const reference to value at the back of the span.

See also
front
Precondition
!is_empty()

◆ contains()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
template<typename Ts , typename Ps , typename Ss >
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::contains ( basic_span< Ts, Ps, Ss >  that) const -> bool
inlinenoexcept

Indicates if this span encloses another span.

See also
encloses
overlaps

◆ data()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
constexpr auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::data ( ) const -> pointer
inlineconstexprnoexcept

Returns a pointer to the start of the span.

See also
begin
end
size

Referenced by eagine::memory::buffer::data().

◆ element() [1/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
template<typename Int >
constexpr auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::element ( Int  index) const -> std::enable_if_t<std::is_integral_v<Int>, std::add_const_t<value_type>&>
inlineconstexprnoexcept

Returns a const reference to value at the specified index.

Precondition
0 <= index < size()

Referenced by eagine::memory::basic_span< const gl_types::ubyte_type >::operator[]().

◆ element() [2/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
template<typename Int >
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::element ( Int  index) -> std::enable_if_t<std::is_integral_v<Int>, value_type&>
inlinenoexcept

Returns a reference to value at the specified index.

Precondition
0 <= index < size()

◆ empty()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
constexpr auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::empty ( ) const -> bool
inlineconstexprnoexcept

Indicates that the span is empty.

See also
is_empty
size

◆ encloses()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::encloses ( const_address  a) const -> bool
inlinenoexcept

Indicates if this span encloses the specified address.

See also
contains

Referenced by eagine::memory::basic_span< const gl_types::ubyte_type >::overlaps().

◆ front() [1/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::front ( ) const -> const value_type&
inlinenoexcept

Returns a const reference to value at the front of the span.

See also
back
Precondition
!is_empty()

Referenced by eagine::msgbus::router_address::operator string_view().

◆ front() [2/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::front ( ) -> value_type&
inlinenoexcept

Returns a reference to value at the front of the span.

See also
back
Precondition
!is_empty()

◆ is_empty()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
constexpr auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::is_empty ( ) const -> bool
inlineconstexprnoexcept

Indicates that the span is empty.

See also
size

◆ operator bool()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
constexpr eagine::memory::basic_span< ValueType, Pointer, SizeType >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Indicates that the span is not empty.

See also
is_empty
size

◆ operator[]() [1/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
template<typename Int >
constexpr auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::operator[] ( Int  index) const -> std::enable_if_t<std::is_integral_v<Int>, std::add_const_t<value_type>&>
inlineconstexprnoexcept

Array subscript operator.

See also
element

◆ operator[]() [2/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
template<typename Int >
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::operator[] ( Int  index) -> std::enable_if_t<std::is_integral_v<Int>, value_type&>
inlinenoexcept

Array subscript operator.

See also
element

◆ overlaps()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
template<typename Ts , typename Ps , typename Ss >
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::overlaps ( const basic_span< Ts, Ps, Ss > &  that) const -> bool
inlinenoexcept

Indicates if this span overlaps with another span.

See also
encloses
contains

◆ ref() [1/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
constexpr auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::ref ( size_type  index) const -> std::add_const_t<value_type>&
inlineconstexprnoexcept

Returns a const reference to value at the specified index.

Precondition
index < size()

Referenced by eagine::memory::basic_span< const gl_types::ubyte_type >::element().

◆ ref() [2/2]

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::ref ( size_type  index) -> value_type&
inlinenoexcept

Returns a reference to value at the specified index.

Precondition
index < size()

◆ reset()

template<typename ValueType , typename Pointer = ValueType*, typename SizeType = span_size_t>
auto eagine::memory::basic_span< ValueType, Pointer, SizeType >::reset ( ) -> auto&
inlinenoexcept

Resets this span.

Postcondition
is_empty()

Referenced by eagine::memory::owned_block::operator=().

◆ size()

Friends And Related Function Documentation

◆ operator<<()

template<typename T , typename P , typename S >
static auto operator<< ( std::ostream &  out,
memory::basic_span< T, P, S >  s 
) -> std:: enable_if_t<std::is_same_v<std::remove_const_t<T>, char>, std::ostream&>
related

Operator for printing spans of string characters into output streams.

See also
write_to_stream

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

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).