对于嵌套模板,`>>`成为标准C ++(而不是`>>`)? [英] For nested templates, when did `>>` become standard C++ (instead of `> >`)?

查看:98
本文介绍了对于嵌套模板,`>>`成为标准C ++(而不是`>>`)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎记得,在处理嵌套模板参数时,在yore的时候,警告不要将两个> 字符相邻(没有空格) 。我甚至模糊地记得宣布任何向量的向量并遇到这个编译错误。

I seem to recall, in times of yore, being warned against putting two > characters right next to each other (without a space) when dealing with nested template parameters. I even vaguely remember declaring vectors of vectors of whatever and encountering this compilation error.

但现在我发现编译可怕的>> ...

But now I find that there is absolutely nothing wrong with compiling the dreaded >>...

我的问题是:

这个公约在什么时候成为可接受的做法?

At what point did this convention become an acceptable practice?

是标准C ++的一部分吗?

Is it part of standard C++?

它是标准的一部分,我在大学使用的编译器(和我的教授)只是不支持它吗?

Was it always part of the standard and the compilers I used (and the professors I had) in college just didn't support it yet?

也许这些问题是一个

推荐答案

用嵌套<$ c关闭的模板$ c>>> 是由即将推出的标准正式支持 C ++ 0x(现在C ++ 11)。以前,你需要的空间,或一个编译器,为你的额外的英里(并没有表示的标准)。

Templates closed with nested >> are officially supported by the upcoming standard C++0x (now C++11). Previously you would need the space, or a compiler that went the extra mile for you (and did things not indicated by the standard).

这个问题源于这样的事实: C中的>> 是右移运算符,它是单个词法令牌,它与两个单独的> 令牌在经典构造的C ++编译器中的解析阶段(并且仅在模板的情况下,而不是当它实际上是右移时)将是需要的。换句话说,>> 如果允许关闭嵌套模板,在词汇上是不明确的,但是这可以(并且正在)通过解析期间的额外复杂性在现代C ++中真的没什么新鲜的)。

The issue stems from the fact that >> in C is the right-shift operator, which is a single lexical token, which conflicts with the two separate > tokens that would be needed during the parsing stage in a classically-constructed C++ compiler (and only in the case of templates, not when it actually is a right-shift). In other words, the >>, if allowed to close nested templates, is lexically ambiguous, but this can be (and is being) addressed by extra sophistication during parsing (which in modern C++ is really nothing new).

这篇关于对于嵌套模板,`&gt;&gt;`成为标准C ++(而不是`&gt;&gt;`)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆