In the vislib we often used this pattern:
some_function(str.AllocateBuffer(size), size);
In the vislib.legacy project I currently replaced that code using a const_cast which is not nice at all!
str = string(size, ' ');
some_function(const_cast<char*>(str.c_str()), size);
It works most of the time, but creates situations with the issue of ticket [#72].
I am currently not sure how to resolve this issue nicely. I am thinking, maybe we could do something with a new shallow_string_buffer class, to at least hide the const_cast. Or maybe we could do something with the string_builder.
I found a nice solution on StackOverflow: http://stackoverflow.com/questions/584824/guaranteed-lifetime-of-temporary-in-c
Implemented
the::text::string_bufferand functionthe::text::string_buffer_allocatesolve this issue (for most cases).Currently not tested on Linux.
I will do that on Monday, and if it works I will close this ticket.