string_view provides a read only view into memory allocated elsewhere and is handy for when
passing around pieces of memory, such as pieces of an HTTP header. It is essentially a pointer and a
length and a quick glance at our internal API will provide numerous places this kind of data is
This implementation is intended to be as similar as possible to the standard version to avoid transition difficulties if / when we upgrade to C++17. For this reason no additional features, regardless of how useful we might find them, have been or will be added to this class.
The only known difference at this time is the literal operator is
""_sv instead of
""sv as it is for
std::string_view. The reason is a compiler limitation which does
not allow non-compiler headers to define literal operators without a leading
_. The use would be
ts::string_view ts_v = "A literal string"_sv; // ts::string_view std::string_view std_v = "A literal string"sv; // std::string_view
If you discover any other differences, that is a bug in our implementation and should be fixed.
For passing instance of
string_view it is reasonable to pass it by value. Examining machine
code shows this is the same cost as passing the pointer and length as two arguments and saves
indirection on in the called code.
There is no shortage of additional reference material available, beyond the basic description noted above, which serves to describe the API and usage of this class, and duplicating it here would serve no purpose.