空白很重要的另一个案例(也许?)

Tom*_*miT 10 c++ syntax whitespace c++11 template-aliases

这是另一种情况,其中空白在C++中很重要,还是编译器错误?以下代码在语法上是否正确?

#include <type_traits>

template <bool cond>
using EnableIf = typename std::enable_if<cond, int>::type;

template <int n, EnableIf<n == 1>=0>
void func()
{}
Run Code Online (Sandbox Code Playgroud)

英特尔C++编写器无法编译它:"类型说明符的无效组合".但是在签名中添加单个空格并且它编译得很好:

template <int n, EnableIf<n == 1> =0>
void func()
{}
Run Code Online (Sandbox Code Playgroud)

And*_*rew 18

这是一个空白很重要的案例.编译器将匹配它可以匹配的最大符号,因此它匹配>=.空格使它按照您的意图进行解析.