Status & Roadmap
Authors & License
Funding U++
Search on this site

SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo



template <class T>

class Buffer : private Moveable< Buffer<T> > 


T    Type of elements stored in Buffer.


Buffer is a simple class used to manage a fixed size plain old C dynamically allocated vector of elements of a specified type. The size of the buffer is specified as a constructor parameter and it can be also reallocated with new size, while loosing all current data.


Buffer is a moveable type with pick (only) transfer semantics. Calling methods of picked Buffer is logic error with the exceptions of:

void Alloc(int size);

void Alloc(int size, const T& in);

void Clear();

void operator=(pick_ Buffer& v);



Constructor Detail



Constructs an empty buffer.



Buffer(size_t size)

Constructs the Buffer with a size number of elements.

T must have default constructor.



Buffer(size_t size, const T& init)

Constructs the Buffer initializing the size elements to the specified value init.

T must have default constructor.



Buffer(pick_ Buffer& v)

Pick constructor. Destroys source container v.




Default destructor.



Buffer(size_t size, std::initializer_list<Tinit)


C++ 11 initialization.



Public Member List


void operator=(pick_ Buffer& v)

Pick operator. Source buffer v is destroyed.



operator T*()

operator const T*() const

T *operator~()

const T *operator~() const

T *Get()

const T *Get() const

T *begin()

const T *begin() const

Returns a pointer to the first element of the Buffer or NULL if the Buffer is empty.



void Alloc(size_t size)

Clears the buffer and allocates it with the new size size. All current elements are lost.

T must have default constructor.



void Alloc(size_t size, const T& in)

Clears the buffer and allocates it with the new size size, using the initialization value in. All current elements are lost.

T must have deep copy constructor.



void Clear()

Clears the buffer to the same state as default constructor. All current elements are destroyed.



bool IsEmpty() const

Returns true if Buffer is empty.



Do you want to contribute?