Or you could just #define STR "Lorem Ipsum" and be sure that it's going to be efficient.
template<char ... chars>
struct const_string {
static std::string get() {
return std::string { chars ... };
}
};
Please don't do this.A certain influential segment of the C and C++ development community, the kind that tends to worship "best practices" and "consistency", has been preaching for years that C preprocessor macros are evil, even in cases where they allow for much clearer code.
I'm not sure these people were born with the ability to experience joy.
That said, yes they can lead to large gains so when they are worth it, go for them. Just mention in the documentation that they are macros, in big letters.
The macros themselves are usually in BIG_LETTERS already... that generally gives it away.