Hello I wanted to poll the public about my idea of doing a string class (like std::string
) that would have a feature of being able to work on buffers provided by the client.
What are the dangers that you forsee ? is it a classic smell ? etcaetera
I mean like so:
char ext[64] = {0};
my::string s(ext, my::string::acquire_RW);
size_t len = s.size();
size_t pos = s.find("zboub");
my::string s2(s); // uses true (alloc+)copy semantic here.
So I forsee 2 strategies: acquire_RW
and acquire_RO
that would permit modification of characters in ext
or not. And in the RO
case for any non-const method, and RW
cases in methods where buffer has to be expanded; it would alloc & copy at this moment only.
In a way, the my::string
type becomes a decorator of the char*
type.
Of course being careful of not freeing the external buffer before the decorator is left as a requirement to the client.
Thanks for sharing your concerns