June 2025
Intermediate to advanced
1093 pages
33h 24m
English
A user-defined literal is a custom suffix that can be appended to strings or sequences of digits. The suffix is a regular identifier. Users can define how a literal is interpreted by overriding a member of the new operator"" family. The family members differ in the parameter types of the respective operator""().
// https://godbolt.org/z/cjx49ef19namespace my { Complex operator"" _i(const char*); // 0+ni Complex operator"" _j(long double); // n+0i Puzzle operator"" _puzzle(const char*, size_t);}using namespace my;Complex imag4 = 4_i; // operator"" _i(const char*)Complex real3 = 3.331_j; // operator"" _j(long double)Puzzle p1 = "oXo" // operator"" _puzzle(const char*, size_t) "XoX"_puzzle;
Listing 23.36 Custom literal ...
Read now
Unlock full access