I have an object for which operator << is defined, myobj.

I want to compress into a buffer, and I know that this can be done with boost. I would prefer a buffer that dynamically resizes, but that only allocates new space, preferably treating discontiguous space brought on by new allocations as though the whole buffer was one piece; I don't want to find that it's copying data at all. So vector won't work as a buffer; there's no need for it to be contiguous, just as fast as possible.

I've been trying to do this with filtering_istreambuf by pushing a bzip2_compressor (any compression filter will work). So far, it's giving me a lot of trouble. I did find an example where a string was passed to a function, but they went through a process where they first moved the string into an stringstream. I don't want to settle for that extra copy either.

What would be nice is to be able to do something like

compressor << myobj

compressor.buf(); //returns compressed myobj output