How does one use a user-defined literal operator on a macro that expands to some literal expression?
e.g.:
std::string operator""_str(const char* sz, std::size_t len)
{
return std::string(sz);
}
Where implementation is something like:
#define expr "expression"
auto str = expr _str;
Adjacent string literals are automatically concatenated ([lex.ext]/8), so
auto str = expr ""_str;
would work.
You need another macro that performs token pasting:
#define CONCAT2(A, B) A##B
#define CONCAT(A, B) CONCAT2(A, B)
auto str = CONCAT(expr, _str);
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With