其他分享
首页 > 其他分享> > C模板角度支架陷阱 – 什么是C 11修复?

C模板角度支架陷阱 – 什么是C 11修复?

作者:互联网

在C 11中,这是现在有效的语法:

vector<vector<float>> MyMatrix;

而以前,它必须这样写(注意空格):

vector<vector<float> > MyMatrix;

我的问题是标准用于允许第一个版本的修复是什么?

可能就像制作>一样简单代币而不是>>?如果不是这样,那么这种方法有什么用呢?

我认为形式像myTemplate< x>> 3>是一个非问题,因为您可以通过执行myTemplate<(x>> 3)>来消除它们的歧义.

解决方法:

通过在解析模板参数时向解析规则添加特殊情况来解决此问题.

C++11 14.2/3: When parsing a template-argument-list, the first non-nested > is taken as the ending delimiter rather than a greater-than operator. Similarly, the first non-nested >> is treated as two consecutive but distinct > tokens, the first of which is taken as the end of the template-argument-list and completes the template-id.

标签:c,templates,tokenize,parsing
来源: https://codeday.me/bug/20190923/1814045.html