A C++11 technique for encoding string literals as unique types using variadic templates, constexpr functions, and preprocessor macros. The approach builds a t_string template parameterized on individual characters, uses a constexpr at() function to index string literals at compile time, and chains append template members to strip trailing null characters. The result allows inheriting from a string literal type with zero runtime overhead, at the cost of increased compile time. Note: the post itself flags this content as outdated.
Table of contents
constexpr and the preprocessor to the rescue! Copy link Link copied!Generalizing on length Copy link Link copied!Getting rid of those zeroes Copy link Link copied!Conclusion Copy link Link copied!Sort: