A substitute for std::vector<char> that has more useful alignment guarantees and explicitly avoids default initialisation of each element.
More...
|
| 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 () |
|
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.