在cppreference上有一个提到,可以有模板化的用户 - 文字运算符,但有一些限制:
如果文字运算符是模板,则它必须具有空参数列表,并且只能有一个模板参数,该参数必须是具有元素类型的非类型模板参数包
char,例如
template <char...> double operator "" _x();
Run Code Online (Sandbox Code Playgroud)
所以我在下面的代码中写了一个:
template <char...>
double operator "" _x()
{
return .42;
}
int main()
{
10_x; // empty template list, how to specify non-empty template parameters?
}
Run Code Online (Sandbox Code Playgroud)
题:
10_x<'a'>;或者10_<'a'>x;不编译.