在N4606 ISO / IEC JTC1 SC22 WG21的标准文件中, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf p.34有一个例子。
long double operator "" _w(long double);
std::string operator "" _w(const char16_t*, std::size_t);
unsigned operator "" _w(const char*);
int main() {
1.2_w; // calls operator "" _w(1.2L)
u"one"_w; // calls operator "" _w(u"one", 3)
12_w; // calls operator "" _w("12")
"two"_w; // error: no applicable literal operator
}
如何创建std :: string运算符的示例"" _w(const char16_t *,std :: size_t);
如何从const char16_t *转换为std :: string。
其他2个功能是这样的。
long double operator "" _w(long double ld){return ld;}
unsigned operator "" _w(const char*cc){return (unsigned)*cc};