9#include <initializer_list>
25 operator T*() {
return buf; }
51 for (
auto v: list)
append(v);
56 T*
begin()
const {
return &buf[0]; }
59 T*
end()
const {
return &buf[
len]; }
64 delete[] buf; buf =
nullptr;
len = 0;
size = 0;
70 for (
size_t i = 0; i <
len; ++i)
append(src[i]);
80 for (
auto el : b)
append(el);
84 if (
this == &b)
return *
this;
90 assert(buf !=
nullptr);
93 for (
auto el: b)
append(el);
104 if (
this == &b)
return *
this;
dynamically allocated, but fixed-size buffer template
Definition buffer.h:18
Buffer & append(T b)
simple append single item
Definition buffer.h:44
Buffer & append(std::initializer_list< T > list)
append multiple items
Definition buffer.h:50
T & at(size_t ix)
access into known length of buffer
Definition buffer.h:29
Buffer & operator=(const Buffer &b)
copy assignment operator
Definition buffer.h:83
T * end()
end method for range-based for loops
Definition buffer.h:58
Buffer(const Buffer &b)
copy constructor
Definition buffer.h:79
Buffer & operator=(Buffer &&b) noexcept
move assignment operator
Definition buffer.h:103
Buffer(const T *src, size_t len, size_t sz=0)
copy from naked array with known length
Definition buffer.h:67
T & operator[](size_t ix)
access into known size of buffer
Definition buffer.h:34
Buffer(size_t sz=0)
constructor with fixed size
Definition buffer.h:77
~Buffer()
destructor
Definition buffer.h:63
size_t size
total capacity of buffer
Definition buffer.h:23
Buffer(std::initializer_list< T > list)
initializer list constructor
Definition buffer.h:73
T & operator[](size_t ix) const
access into known size of buffer
Definition buffer.h:39
T * begin()
begin method for range-based for loops
Definition buffer.h:55
Buffer(Buffer &&b) noexcept
move constructor
Definition buffer.h:97
size_t len
number of items stored in buffer
Definition buffer.h:21