Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

For nested templates, when did `>>` become standard C++ (instead of `> >`)?

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 >>...

My question(s) are thus:

At what point did this convention become an acceptable practice?

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?

Maybe these questions are a tad bit historical, but for me it seems that proper historical context makes actual remembering trivial.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...