I'm playing with an idea of an immutable string class in C++11.
One of the features I would like to have would be an ability to work with borrowed memory, where the user would promise during initialization that the buffer containing data will not change and will live longer than the string object. This type of initialization would probably be quite rare in practice so it would mainly be accessible through a static method.
For convenience however I would like constructions like ImmutableString("abc")
to end up using the borrowed memory, since with string literals I can actually be sure about lifetime and constness of the value.
Is there a way to determine if a parameter is a string literal?
An overload to const char[]
is not enough since it can be automatically cast from plain char[]
and the lifetime is not guaranteed in any way.