Buffer module

This module provides buffer implemention as defined in N4771 Networking TS draft's 'Buffer' section.

Contents

Buffers are built upon gsl::span, and the buffers all inherit from spans. See ark::base_buffer for details. gsl::span has bound checks, which also make buffers of this module 'safe buffers' with bound checks, too.

for more information about gsl: https://github.com/microsoft/GSL/

Classes

template<typename CharT>
class ark::base_buffer
base type for mutable_buffer and const_buffer

Typedefs

using mutable_buffer = base_buffer<char>
a view to a span of memory as mutable buffer
using const_buffer = base_buffer<const char>
a view to a span of memory as const buffer
template<typename T>
using is_mutable_buffer_sequence = decltype(detail::is_mutable_buffer_sequence_impl<T>(0))
std::true_type if T is a MutableBufferSequence
template<typename T>
using is_const_buffer_sequence = decltype(detail::is_const_buffer_sequence_impl<T>(0))
std::true_type if T is a ConstBufferSequence

Functions

auto operator+(const mutable_buffer& b, size_t n) -> mutable_buffer noexcept
returns an ascended buffer by n bytes
auto operator+(size_t n, const mutable_buffer& b) -> mutable_buffer noexcept
returns an ascended buffer by n bytes
auto operator+(const const_buffer& b, size_t n) -> const_buffer noexcept
returns an ascended buffer by n bytes
auto operator+(size_t n, const const_buffer& b) -> const_buffer noexcept
returns an ascended buffer by n bytes
auto buffer(void* p, size_t n) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
auto buffer(const void* p, size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
auto buffer(const mutable_buffer& b) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
auto buffer(const mutable_buffer& b, size_t n) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
auto buffer(const const_buffer& b) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
auto buffer(const const_buffer& b, size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(T(&data)[N]) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(const T(&data)[N]) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(array<T, N>& data) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(array<const T, N>& data) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, class Allocator>
auto buffer(vector<T, Allocator>& data) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, class Allocator>
auto buffer(const vector<T, Allocator>& data) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class CharT, class Traits, class Allocator>
auto buffer(basic_string<CharT, Traits, Allocator>& data) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class CharT, class Traits, class Allocator>
auto buffer(const basic_string<CharT, Traits, Allocator>& data) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class CharT, class Traits>
auto buffer(basic_string_view<CharT, Traits> data) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(T(&data)[N], size_t n) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(const T(&data)[N], size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(array<T, N>& data, size_t n) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, size_t N>
auto buffer(array<const T, N>& data, size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, class Allocator>
auto buffer(vector<T, Allocator>& data, size_t n) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class T, class Allocator>
auto buffer(const vector<T, Allocator>& data, size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class CharT, class Traits, class Allocator>
auto buffer(basic_string<CharT, Traits, Allocator>& data, size_t n) -> mutable_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class CharT, class Traits, class Allocator>
auto buffer(const basic_string<CharT, Traits, Allocator>& data, size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
template<class CharT, class Traits>
auto buffer(basic_string_view<CharT, Traits> data, size_t n) -> const_buffer noexcept
creates a ark::mutable_buffer or ark::const_buffer
auto buffer_sequence_begin(const mutable_buffer& b) -> const mutable_buffer* noexcept
returns an iterator to the first buffer of ConstBufferSequence
auto buffer_sequence_begin(const const_buffer& b) -> const const_buffer* noexcept
returns an iterator to the first buffer of ConstBufferSequence
template<class C>
auto buffer_sequence_begin(C& c) -> auto noexcept
returns an iterator to the first buffer of ConstBufferSequence
template<class C>
auto buffer_sequence_begin(const C& c) -> auto noexcept
returns an iterator to the first buffer of ConstBufferSequence
auto buffer_sequence_end(const mutable_buffer& b) -> const mutable_buffer* noexcept
returns an iterator past the last buffer of BufferSequence
auto buffer_sequence_end(const const_buffer& b) -> const const_buffer* noexcept
returns an iterator past the last buffer of BufferSequence
template<class C>
auto buffer_sequence_end(C& c) -> auto noexcept
returns an iterator past the last buffer of BufferSequence
template<class C>
auto buffer_sequence_end(const C& c) -> auto noexcept
returns an iterator past the last buffer of BufferSequence
template<class ConstBufferSequence>
auto buffer_size(const ConstBufferSequence& buffers) -> size_t noexcept
returns the sum size of a ConstBufferSequence
template<class MutableBufferSequence, class ConstBufferSequence>
auto buffer_copy(const MutableBufferSequence& dest, const ConstBufferSequence& source, size_t max_size) -> size_t
copy the underlying bytes from one buffer to another

Variables

template<typename T>
bool is_mutable_buffer_sequence_v constexpr
helper for is_mutable_buffer_sequence::value
template<typename T>
bool is_const_buffer_sequence_v constexpr
helper for is_const_buffer_sequence::value

Typedef documentation

using mutable_buffer = base_buffer<char>

a view to a span of memory as mutable buffer

using const_buffer = base_buffer<const char>

a view to a span of memory as const buffer

template<typename T>
using is_mutable_buffer_sequence = decltype(detail::is_mutable_buffer_sequence_impl<T>(0))

std::true_type if T is a MutableBufferSequence

std::false_type otherwise.

A MutableBufferSequence denotes a type convertible to ark::mutable_buffer, or an iterable of it.

template<typename T>
using is_const_buffer_sequence = decltype(detail::is_const_buffer_sequence_impl<T>(0))

std::true_type if T is a ConstBufferSequence

std::false_type otherwise.

A ConstBufferSequence denotes a type convertible to ark::const_buffer, or an iterable of it.

By theory, a MutableBufferSequence is a ConstBufferSequence, but there's no vice-versa.

Function documentation

mutable_buffer operator+(const mutable_buffer& b, size_t n) noexcept

returns an ascended buffer by n bytes

mutable_buffer operator+(size_t n, const mutable_buffer& b) noexcept

returns an ascended buffer by n bytes

const_buffer operator+(const const_buffer& b, size_t n) noexcept

returns an ascended buffer by n bytes

const_buffer operator+(size_t n, const const_buffer& b) noexcept

returns an ascended buffer by n bytes

mutable_buffer buffer(void* p, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

const_buffer buffer(const void* p, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

mutable_buffer buffer(const mutable_buffer& b) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

mutable_buffer buffer(const mutable_buffer& b, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

const_buffer buffer(const const_buffer& b) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

const_buffer buffer(const const_buffer& b, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
mutable_buffer buffer(T(&data)[N]) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
const_buffer buffer(const T(&data)[N]) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
mutable_buffer buffer(array<T, N>& data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
const_buffer buffer(array<const T, N>& data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, class Allocator>
mutable_buffer buffer(vector<T, Allocator>& data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, class Allocator>
const_buffer buffer(const vector<T, Allocator>& data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class CharT, class Traits, class Allocator>
mutable_buffer buffer(basic_string<CharT, Traits, Allocator>& data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class CharT, class Traits, class Allocator>
const_buffer buffer(const basic_string<CharT, Traits, Allocator>& data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class CharT, class Traits>
const_buffer buffer(basic_string_view<CharT, Traits> data) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
mutable_buffer buffer(T(&data)[N], size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
const_buffer buffer(const T(&data)[N], size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
mutable_buffer buffer(array<T, N>& data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, size_t N>
const_buffer buffer(array<const T, N>& data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, class Allocator>
mutable_buffer buffer(vector<T, Allocator>& data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class T, class Allocator>
const_buffer buffer(const vector<T, Allocator>& data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class CharT, class Traits, class Allocator>
mutable_buffer buffer(basic_string<CharT, Traits, Allocator>& data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class CharT, class Traits, class Allocator>
const_buffer buffer(const basic_string<CharT, Traits, Allocator>& data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

template<class CharT, class Traits>
const_buffer buffer(basic_string_view<CharT, Traits> data, size_t n) noexcept

creates a ark::mutable_buffer or ark::const_buffer

depending on the undelying type, creates a ark::mutable_buffer or ark::const_buffer, an additional size_t could also be served to limit the size of the buffer returned.

const mutable_buffer* buffer_sequence_begin(const mutable_buffer& b) noexcept

returns an iterator to the first buffer of ConstBufferSequence

returns std::addressof(b) for buffers, and c.begin() for iterables of buffers

const const_buffer* buffer_sequence_begin(const const_buffer& b) noexcept

returns an iterator to the first buffer of ConstBufferSequence

returns std::addressof(b) for buffers, and c.begin() for iterables of buffers

template<class C>
auto buffer_sequence_begin(C& c) noexcept

returns an iterator to the first buffer of ConstBufferSequence

returns std::addressof(b) for buffers, and c.begin() for iterables of buffers

template<class C>
auto buffer_sequence_begin(const C& c) noexcept

returns an iterator to the first buffer of ConstBufferSequence

returns std::addressof(b) for buffers, and c.begin() for iterables of buffers

const mutable_buffer* buffer_sequence_end(const mutable_buffer& b) noexcept

returns an iterator past the last buffer of BufferSequence

returns std::addressof(b)+1 for buffers, and c.end() for iterables of buffers

const const_buffer* buffer_sequence_end(const const_buffer& b) noexcept

returns an iterator past the last buffer of BufferSequence

returns std::addressof(b)+1 for buffers, and c.end() for iterables of buffers

template<class C>
auto buffer_sequence_end(C& c) noexcept

returns an iterator past the last buffer of BufferSequence

returns std::addressof(b)+1 for buffers, and c.end() for iterables of buffers

template<class C>
auto buffer_sequence_end(const C& c) noexcept

returns an iterator past the last buffer of BufferSequence

returns std::addressof(b)+1 for buffers, and c.end() for iterables of buffers

template<class ConstBufferSequence>
size_t buffer_size(const ConstBufferSequence& buffers) noexcept

returns the sum size of a ConstBufferSequence

time complexity O(sizeof(buffers))

template<class MutableBufferSequence, class ConstBufferSequence>
size_t buffer_copy(const MutableBufferSequence& dest, const ConstBufferSequence& source, size_t max_size)

copy the underlying bytes from one buffer to another

Parameters
dest
source
max_size in the max bytes allowed to copy

Variable documentation

template<typename T>
bool is_mutable_buffer_sequence_v constexpr

helper for is_mutable_buffer_sequence::value

template<typename T>
bool is_const_buffer_sequence_v constexpr

helper for is_const_buffer_sequence::value