I'm using a wrapper class around std::string, but what's the easiest/cleanest/most complete way to initialize/construct it. I need at least 3 ways
- From string literals
- From std::string rvalues, avoiding copy!?
- From string_view and string (yes, copy)
The naive programmer would just want to auto-delegate any construction to std::string, but that's not a feature.
struct SimpleString
{
SimpleString() = default;
template<typename T>
SimpleString( T t ) : Text( t ) { } // <==== experimental
// Alternative: are these OK
SimpleString( const char* text ) : Text( text ) { }
SimpleString( std::string&& text ) : Text( text ) { }
SimpleString( const std::string_view text ) : Text( text ) { }
std::string Text;
};
Preemptive note: Yes, I want it and I need it. Use case: call a generic function where SimpleString is treated differently from std::string.
Note regarding inheriting from std::string: Probably a bad idea because implicit conversions will occur at the first opportunity.