This shows you the differences between two versions of the page.
— |
cplusplus:string_view [2022/04/28 22:23] (current) dblume created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== String_view for objects with a const string field ====== | ||
+ | Store a little string in an object which is going to be its name. It can't change its name, so it ought to be const. Prefer not to use std::string - it's heavyweight, | ||
+ | |||
+ | |||
+ | <code c++> | ||
+ | struct Str { | ||
+ | constexpr Str(std:: | ||
+ | auto buf = std:: | ||
+ | std:: | ||
+ | return buf; | ||
+ | }()}, sv{buf.data()} {} | ||
+ | |||
+ | std:: | ||
+ | std:: | ||
+ | }; | ||
+ | </ |