I think this solution would be better: a class that would be templated by the number of std::string elements it holds, and a specialization for 0, where the buffer will be dynamic. What do you think about it?
it will not have undefined behavior :) inheriting from standard library containers is UB. Even though the inheriter doesn't have any data members added on top of the base class
I mean if I construct temporary derived object in place with a call like f(MyString("")), then it will be bound to const reference and will be destructed with an improper destructor.
should we update our goals? 1. We need to stream objects. 2. We need to retrieve the data, flush the stream, and give the data to the caller. 3. We need to figure out when we should delete/override the buffer. Am I right?
I think so. I'd prefer to keed the syntax but make it more resistant to incorrect usage.
I guess I can create a class with a single std::string field and implicit conversions to std::string and char *. Maybe also an overloaded -> to access std::string members. And return that instead.
I think I'll still use static buffers, but I will return a proxy object with a pointer to one of those buffers and add implicit conversions to char * and std::string &&.
The original idea was that std::string ctors and assignment operators would prefer std::string && thus moving the string efficiently. But it turns that those ctors and assignments are ambiguous.
I start to think that it's impossible. If I have both casts, then std::string ctors and ='s calls are ambiguous. If I have only char * cast. then I get copies instead of moves (as before). std::string && will allow me to move, but it will prevent me from assigning the result to char *, which is very bad.
I think the problem is not so significant, so it would be better to work on something more significant. Nothing can be done to predict when the pointer should be freed
should it produce something else? It's just making the code prettier and stable. Everyone knows what queue is, but not everyone will immediately understand what you are trying to achieve by your code
Uh, I don't want to mess with that anymore. Any decent improvements to it would take too many time and wont worth it. Going to do something *interesting* now, like learning how to do proper vector graphics over OpenGL using something like NanoVG.