I need a buffer class. I found "std::vector" pretty useful, but I don't like, for example, to do this:
typedef std::vector<char> Buffer;
Buffer buff1;
Buffer buff2;
...
buff1.insert(buff1.end(), buff2.begin(), buff2.end())
Each time I want to append... I would like to have some concat method, something like:
buff1.append(buff2)
or an operator+= or something.
Now, I've tried to add this method:
void append(dataStructures::Buffer& self, const dataStructures::Buffer& other)
{
self.insert(self.end(), other.begin(), other.end());
}
and call it simply by: buff1.append(buff2)
but it won't compile, for the reason:std::vector<byte, std::allocator<byte>>" has no member "append"
. That is right. I've also tried to get "self" as a pointer, with no success. It does work when adding operator<< to the std::ostream, so I really expected it to work, but I was wrong.
I can, of course, create a Buffer using the inheritance mechanism, but std containers have no virtual Dtor, so that might be a bad idea (Although I'm not adding any member variables... still a bad idea).
Is there any way to do what I want? I know it's only a matter of readability, but it is important for me. I'm wondering if there is a simple solution, or my only option is to implement a proxy class or a whole new Buffer class (I've tried to use boost's Buffer, but it doesn't allocate memory, as much as I understood).
Thank you very much.