I am developing libraries with tons of static strings inside. To optimize the runtime a bit, this shall be changed from null-terminated strings (classic C-style char arrays) to pre-known-length structures, like std::string or std::string_view or custom pointer+length-pairs. std::string is well known and versatile but has the disadvantage of heavy footprint (at least 32bit on x64) plus VM overhead (heap and runtime cost) if the Small-String-Optimization is not applicable, which hits most of my data. string_view sounds like the best candidate, as long as I can be sure that data is null-terminated (despite of no such guarantee from string_view itself, the risk can be mitigated by conventions).
The questions which still matters much: do modern compilers pre-initialize string_view without using internal strlen, i.e. with constant complexity and not O^(n)? If they do, is the null-terminator preserved?
I could, of course, add some macro to initialize the string_views but that would be cumbersome. Something like:
#define foo(buf) foo, (sizeof(foo)-1)
const string_view svMyVar(foo("original C-string value"));
I hope that compiler would simplify that for me.