E-MailRelay

Public Types | Public Member Functions | List of all members
G::Buffer< T > Struct Template Reference

A substitute for std::vector<char> that has more useful alignment guarantees and explicitly avoids default initialisation of each element. More...

`#include <gbuffer.h>`

## Public Types
using | value_type = T
using | iterator = T *
using | const_iterator = const T *

## Public Member Functions
| Buffer (std::size_t n)
void | reserve (std::size_t n)
void | resize (std::size_t n)
const T & | operator[] (std::size_t i) const noexcept
T & | operator[] (std::size_t i) noexcept
const T & | at (std::size_t i) const
T & | at (std::size_t i)
std::size_t | size () const noexcept
std::size_t | capacity () const noexcept
bool | empty () const noexcept
void | clear () noexcept
void | shrink_to_fit () noexcept
iterator | begin () noexcept
iterator | end () noexcept
const value_type * | data () const noexcept
value_type * | data () noexcept
const_iterator | begin () const noexcept
const_iterator | end () const noexcept
const_iterator | cbegin () const noexcept
const_iterator | cend () const noexcept
iterator | erase (iterator range_begin, iterator range_end) noexcept
template<typename U >
void | insert (iterator p, U range_begin, U range_end)
template<typename U >
void | insert (iterator p, U *range_begin, U *range_end)
void | swap (Buffer< T > &other) noexcept
| Buffer (const Buffer< T > &other)
| Buffer (Buffer< T > &&other) noexcept
Buffer< T > & | operator= (const Buffer< T > &other)
Buffer< T > & | operator= (Buffer< T > &&other) noexcept
template<typename U >
T * | aligned ()

## Detailed Description

template<typename T>
struct G::Buffer< T >

A substitute for std::vector<char> that has more useful alignment guarantees and explicitly avoids default initialisation of each element.

The alignment is that of std::malloc(), ie. std::max_align_t. (See also posix_memalign().)

The buffer_cast() free function can be used to return a pointer to the start of the buffer for some aggregate type, throwing if the buffer is too small for a complete object:

Buffer<char> buffer( 100 ) ;
auto n = fill( buffer ) ;
buffer.resize( n ) ;
Foo * foo_p = buffer_cast<Foo*>( buffer ) ;
foo_p->~Foo() ;

The implementation of buffer_cast uses placement-new in order to avoid the undefined behaviour of a pointer cast. In some cases this means that the destructor should be called explicitly through the pointer.

Definition at line 59 of file gbuffer.h.

## Member Typedef Documentation

## ◆ const_iterator

template<typename T >

using G::Buffer< T >::const_iterator = const T *

Definition at line 64 of file gbuffer.h.

## ◆ iterator

template<typename T >

using G::Buffer< T >::iterator = T *

Definition at line 63 of file gbuffer.h.

## ◆ value_type

template<typename T >

using G::Buffer< T >::value_type = T

Definition at line 62 of file gbuffer.h.

## Constructor & Destructor Documentation

## ◆ Buffer() [1/3]

template<typename T >

G::Buffer< T >::Buffer | ( | std::size_t | n | ) |
| inline explicit

Definition at line 66 of file gbuffer.h.

## ◆ ~Buffer()

template<typename T >

G::Buffer< T >::~Buffer | ( |  | ) |
| inline

Definition at line 71 of file gbuffer.h.

## ◆ Buffer() [2/3]

template<typename T >

G::Buffer< T >::Buffer | ( | const Buffer< T > & | other | ) |
| inline

Definition at line 141 of file gbuffer.h.

## ◆ Buffer() [3/3]

template<typename T >

G::Buffer< T >::Buffer | ( | Buffer< T > && | other | ) |
| inline noexcept

Definition at line 149 of file gbuffer.h.

## Member Function Documentation

## ◆ aligned()

template<typename T >
template<typename U >

T * G::Buffer< T >::aligned | ( |  | ) |
| inline

Definition at line 163 of file gbuffer.h.

## ◆ at() [1/2]

template<typename T >

T & G::Buffer< T >::at | ( | std::size_t | i | ) |
| inline

Definition at line 88 of file gbuffer.h.

## ◆ at() [2/2]

template<typename T >

const T & G::Buffer< T >::at | ( | std::size_t | i | ) | const
| inline

Definition at line 87 of file gbuffer.h.

## ◆ begin() [1/2]

template<typename T >

const_iterator G::Buffer< T >::begin | ( |  | ) | const
| inline noexcept

Definition at line 98 of file gbuffer.h.

## ◆ begin() [2/2]

template<typename T >

iterator G::Buffer< T >::begin | ( |  | ) |
| inline noexcept

Definition at line 94 of file gbuffer.h.

## ◆ capacity()

template<typename T >

std::size_t G::Buffer< T >::capacity | ( |  | ) | const
| inline noexcept

Definition at line 90 of file gbuffer.h.

## ◆ cbegin()

template<typename T >

const_iterator G::Buffer< T >::cbegin | ( |  | ) | const
| inline noexcept

Definition at line 100 of file gbuffer.h.

## ◆ cend()

template<typename T >

const_iterator G::Buffer< T >::cend | ( |  | ) | const
| inline noexcept

Definition at line 101 of file gbuffer.h.

## ◆ clear()

template<typename T >

void G::Buffer< T >::clear | ( |  | ) |
| inline noexcept

Definition at line 92 of file gbuffer.h.

## ◆ data() [1/2]

template<typename T >

const value_type * G::Buffer< T >::data | ( |  | ) | const
| inline noexcept

Definition at line 96 of file gbuffer.h.

## ◆ data() [2/2]

template<typename T >

value_type * G::Buffer< T >::data | ( |  | ) |
| inline noexcept

Definition at line 97 of file gbuffer.h.

## ◆ empty()

template<typename T >

bool G::Buffer< T >::empty | ( |  | ) | const
| inline noexcept

Definition at line 91 of file gbuffer.h.

## ◆ end() [1/2]

template<typename T >

const_iterator G::Buffer< T >::end | ( |  | ) | const
| inline noexcept

Definition at line 99 of file gbuffer.h.

## ◆ end() [2/2]

template<typename T >

iterator G::Buffer< T >::end | ( |  | ) |
| inline noexcept

Definition at line 95 of file gbuffer.h.

## ◆ erase()

template<typename T >

iterator G::Buffer< T >::erase | ( | iterator | range_begin,
|  | iterator | range_end
| ) |  |
| inline noexcept

Definition at line 102 of file gbuffer.h.

## ◆ insert() [1/2]

template<typename T >
template<typename U >

void G::Buffer< T >::insert | ( | iterator | p,
|  | U * | range_begin,
|  | U * | range_end
| ) |  |
| inline

Definition at line 126 of file gbuffer.h.

## ◆ insert() [2/2]

template<typename T >
template<typename U >

void G::Buffer< T >::insert | ( | iterator | p,
|  | U | range_begin,
|  | U | range_end
| ) |  |
| inline

Definition at line 117 of file gbuffer.h.

## ◆ operator=() [1/2]

template<typename T >

Buffer< T > & G::Buffer< T >::operator= | ( | Buffer< T > && | other | ) |
| inline noexcept

Definition at line 158 of file gbuffer.h.

## ◆ operator=() [2/2]

template<typename T >

Buffer< T > & G::Buffer< T >::operator= | ( | const Buffer< T > & | other | ) |
| inline

Definition at line 153 of file gbuffer.h.

## ◆ operator[]() [1/2]

template<typename T >

const T & G::Buffer< T >::operator[] | ( | std::size_t | i | ) | const
| inline noexcept

Definition at line 85 of file gbuffer.h.

## ◆ operator[]() [2/2]

template<typename T >

T & G::Buffer< T >::operator[] | ( | std::size_t | i | ) |
| inline noexcept

Definition at line 86 of file gbuffer.h.

## ◆ reserve()

template<typename T >

void G::Buffer< T >::reserve | ( | std::size_t | n | ) |
| inline

Definition at line 75 of file gbuffer.h.

## ◆ resize()

template<typename T >

void G::Buffer< T >::resize | ( | std::size_t | n | ) |
| inline

Definition at line 84 of file gbuffer.h.

## ◆ shrink_to_fit()

template<typename T >

void G::Buffer< T >::shrink_to_fit | ( |  | ) |
| inline noexcept

Definition at line 93 of file gbuffer.h.

## ◆ size()

template<typename T >

std::size_t G::Buffer< T >::size | ( |  | ) | const
| inline noexcept

Definition at line 89 of file gbuffer.h.

## ◆ swap()

template<typename T >

void G::Buffer< T >::swap | ( | Buffer< T > & | other | ) |
| inline noexcept

Definition at line 135 of file gbuffer.h.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/glib/gbuffer.h