There are suggestions to add string_view in C ++ to the upcoming standard.
A string_view is an unnamed iterative range over characters with many utilities and properties that you expect from a string class, except that you cannot insert / delete characters (and editable characters are often blocked in some subtypes).
I would suggest trying this approach - write your own (in your own namespace). (In any case, you should have your own namespace for generic code snippets.)
The main data is a couple of versions of char* pr std::string::iterator (or const ). If the user needs a zero-terminated buffer, the to_string method allocates one. I would start with non-mutable ( const ) character data. Remember to begin and end : this makes your view iterable with for(:) loops.
This construct has the danger that the original std::string must persist long enough to survive all representations.
If you are ready to give up any performance for security, you have a view std::shared_ptr<const std::string> that it can move std::string to, and as a first step move the entire buffer to it, and then start grinding / disassembling it. (child views create a new common pointer to the same data). Then your view class is more like an immutable row with a shared repository.
The top of the shared_ptr<const> version includes security, a longer viewing life (no longer depends on life expectancy), and you can easily redirect methods like const substring std::string so that you can write less code.
Disadvantages include possible incompatibilities with the input standard value of 1 and lower performance, as you drag shared_ptr around.
I suspect that looks and ranges will be of increasing importance in modern C ++ with upcoming and recent improvements in the language.
boost::string_ref apparently an implementation of a proposal for the C ++ 1y standard.
1 however, given how easy it is to add features to the metaprogramming of the template, having the template argument "resource owner" for the presentation type may be a good design decision. Then you can have your own and not owning string_view with another identical semantics ...