c++ - `>>>` 如何在 C++0x 中进行词法分析?

标签 c++ c++11

>>> 的词法是 >>>。但是如果第一个 > 关闭模板参数列表会发生什么,结果应该等同于 >> > 还是 >>>

在下面的代码中确实很重要:

template<class T> struct X { };

void operator >>(const X<int>&, int) { }

int main() {
    *new X<int>>> 1;
}

最佳答案

FDIS 的文本说

Similarly, the first non-nested >> is treated as two consecutive but distinct > tokens

它不能解除标记和 relex。所以这将是一个 >> >。请注意,C++ 实现的输入首先被转换为预处理标记,然后这些标记被转换为 C++ 标记。因此,首先您的输入是 C++ 标记 >>>,然后 C++ 解析器将这些标记更改为 >> >

Each preprocessing token is converted into a token. (2.7). The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. [ Note: The process of analyzing and translating the tokens may occasionally result in one token being replaced by a sequence of other tokens (14.2). — end note ]

您不可能合并这两个尾随 >> 标记。

关于c++ - `>>>` 如何在 C++0x 中进行词法分析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235907/

相关文章:

c++ - 通过引用使用 vector<int>::iterator 但有错误

c++ - 如何在特定的内存位置写入数据? C++

没有类型推导的 LValue 和 Rvalue 的 C++ 引用

c++ - 发送/接收套接字阻塞问题

c++ - 如何处理 wxWidgets 控制台应用程序中的关键事件?

c++ - 在 Qt 中解析 HTML 的最佳方法是什么?

c++ - 我应该为赋值运算符使用左值引用限定符吗?

c++ - 另一个别名的模板别名

c++ - 构造一个对象以在其他地方按值返回

c++ - 为什么当我输入 12 位数字时,以下代码会崩溃?