|
LibSWOC++ 1.5.14
Solid Wall of C++
|
#include <MemSpan.h>


Public Types | |
| using | value_type = T |
| Element type for span. | |
| using | iterator = T * |
| Iterator. | |
| using | const_iterator = T const * |
| Constant iterator. | |
Public Member Functions | |
| constexpr | MemSpan ()=default |
| Default constructor (empty buffer). | |
| constexpr | MemSpan (self_type const &that)=default |
| Copy constructor. | |
| constexpr | MemSpan (self_type &that)=default |
| Copy constructor. | |
| constexpr | MemSpan (value_type *ptr, size_t count) |
| constexpr | MemSpan (value_type *begin, value_type *end) |
| template<auto N> | |
| constexpr | MemSpan (T(&a)[N]) |
| template<auto N, typename U, typename META = std::enable_if_t<std::conjunction_v<std::is_const<T>, std::is_same<std::remove_const_t<U>, std::remove_const_t<T>>>>> | |
| constexpr | MemSpan (std::array< U, N > const &a) |
| template<auto N> | |
| constexpr | MemSpan (std::array< T, N > &a) |
| template<typename U, typename META = std::enable_if_t<std::conjunction_v<std::is_const<T>, std::is_same<U, std::remove_const_t<T>>>>> | |
| constexpr | MemSpan (MemSpan< U > const &that) |
| template<typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), T *> && std::is_convertible_v<decltype(std::declval<C>().size()), size_t>> | |
| constexpr | MemSpan (C &c) |
| template<typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), T *> && std::is_convertible_v<decltype(std::declval<C>().size()), size_t>> | |
| constexpr | MemSpan (C const &c) |
| constexpr | MemSpan (std::nullptr_t) |
| constexpr bool | operator== (self_type const &that) const |
| bool | is_same (self_type const &that) const |
| constexpr bool | operator!= (self_type const &that) const |
| self_type & | operator= (self_type const &that)=default |
| Assignment - the span is copied, not the content. | |
| T & | operator[] (size_t idx) const |
| Access element at index idx. | |
| bool | operator! () const |
| operator bool () const | |
| constexpr bool | empty () const |
| template<typename... Args> | |
| auto | make (Args &&...args) -> self_type & |
| template<typename U> | |
| constexpr | MemSpan (MemSpan< U > const &that) |
| template<auto N, typename U> | |
| constexpr | MemSpan (U(&a)[N]) |
| auto | rebind () const -> self_type |
Protected Attributes | |
| T * | _ptr = nullptr |
| Pointer to base of memory chunk. | |
| size_t | _count = 0 |
| Number of elements. | |
Accessors. | |
| constexpr T * | begin () const |
| Pointer to the first element in the span. | |
| constexpr T * | end () const |
| Pointer to first element not in the span. | |
| constexpr size_t | size () const |
| Number of elements in the span. | |
| constexpr size_t | count () const |
| constexpr size_t | length () const |
| Number of elements in the span. | |
| constexpr size_t | data_size () const |
| Number of bytes in the span. | |
| T * | data () const |
| constexpr T * | data_end () const |
| T & | front () |
| T & | back () |
| template<typename F> | |
| self_type & | apply (F &&f) |
| template<typename U = std::conditional_t<std::is_const_v<T>, void const, void>> | |
| MemSpan< U > | rebind () const |
| self_type & | assign (T *ptr, size_t count) |
| self_type & | assign (T *first, T const *last) |
| self_type & | clear () |
| Clear the span (become an empty span). | |
| bool | contains (value_type const *p) const |
| constexpr self_type | prefix (size_t count) const |
| constexpr self_type | first (size_t count) const |
| self_type & | remove_prefix (size_t count) |
| self_type | clip_prefix (size_t count) |
| constexpr self_type | suffix (size_t count) const |
| constexpr self_type | last (size_t count) const |
| self_type & | remove_suffix (size_t count) |
| self_type | clip_suffix (size_t count) |
| constexpr self_type | subspan (size_t offset, size_t count) const |
| constexpr self_type & | restrict (size_t n) |
| template<typename... Args> | |
| self_type & | make (Args &&...args) |
| void | destroy () |
| Destruct all elements in the span. | |
A span of contiguous piece of memory.
A MemSpan does not own the memory to which it refers, it is simply a span of part of some (presumably) larger memory object. It acts as a pointer, not a container - copy and assignment change the span, not the memory to which the span refers.
The purpose is that frequently code needs to work on a specific part of the memory. This can avoid copying or allocation by allocating all needed memory at once and then working with it via instances of this class.
const correctness is tricky. Because this class is intended as a "smart" pointer, its constancy does not carry over to its elements, just as a constant pointer doesn't make its target constant. This makes it different than containers such as std::array or std::vector. This means when creating an instance based on such containers the constancy of the container affects the element type of the span. E.g.std::array<T,N> maps to a MemSpan<T> const std::array<T,N> maps to a MemSpan<const T> For convenience a MemSpan<const T> can be constructed from a MemSpan<T> because this maintains const correctness and models how a T const* can be constructed from a T* .
| using swoc::MemSpan< T >::const_iterator = T const * |
| using swoc::MemSpan< T >::iterator = T * |
| using swoc::MemSpan< T >::value_type = T |
|
inlineconstexpr |
|
inlineconstexpr |
|
constexpr |
|
constexpr |
|
inlineconstexpr |
|
constexpr |
Construct from any vector like container.
| C | Container type. |
| c | container |
The container type must have the methods data and size which must return values convertible to the pointer type for T and size_t respectively.
|
inlineconstexpr |
|
constexpr |
|
constexpr |
| MemSpan< T >::self_type & swoc::MemSpan< T >::apply | ( | F && | f | ) |
|
inline |
|
inline |
| T & swoc::MemSpan< T >::back | ( | ) |
|
constexpr |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
| void swoc::MemSpan< T >::destroy | ( | ) |
|
inlineconstexpr |
|
constexpr |
|
constexpr |
| T & swoc::MemSpan< T >::front | ( | ) |
|
inline |
|
constexpr |
|
inlineconstexpr |
| self_type & swoc::MemSpan< T >::make | ( | Args &&... | args | ) |
Construct all elements in the span.
For each element in the span, construct an instance of the span type using the args. If the instances need destruction this must be done explicitly.
| auto swoc::MemSpan< T >::make | ( | Args &&... | args | ) | -> self_type & |
|
inlineexplicit |
|
inline |
|
inlineconstexpr |
|
inlineconstexprdefault |
|
inlineconstexpr |
| T & swoc::MemSpan< T >::operator[] | ( | size_t | idx | ) | const |
|
inlineconstexpr |
Make a copy of this span on the same memory but of type U.
| U | Type for the created span. |
MemSpan which contains the same memory as instances of U.if no type is specified, the default is void or void const according to whether value_type is const.
|
inline |
|
inline |
|
inline |
|
constexpr |
|
inlineconstexpr |
|
inlineconstexpr |
Return a sub span of this span.
| offset | Offset (index) of first element in subspan. |
| count | Number of elements in the subspan. |
The result is clipped by this - if offset is out of range an empty span is returned. Otherwise count is clipped by the number of elements available in this.
|
inlineconstexpr |
|
protected |
|
protected |