I think you will be frowned upon by the purists of STD cult for doing this. In any case, its much better to not relay on bloated and generic standard library if you want dynamic string type that can be easily passed to low level API functions that will modify its buffer and size at the same time, without any conversions, than you will have to implement it! Its actually very challenging and interesting task to do. For example in my custom txt
type I overload this operators:
ui64 operator~() const; // Size operator
uli32 * operator*(); // Size modification operator
ui64 operator!() const; // True Size Operator
txt& operator--(); // Trimm operator
And also this casts:
operator const char *() const;
operator char *();
And as such, i can pass txt
type to low level API functions directly, without even calling any .c_str()
. I can then also pass the API function it's true size (i.e. size of buffer) and also pointer to internal size variable (operator*()
), so that API function can update amount of characters written, thus giving valid string without the need to call stringlength
at all!
I tried to mimic basic types with this txt
, so it has no public functions at all, all public interface is only via operators. This way my txt
fits perfectly with int
s and other fundamental types.