Template within template: why "`>>' should be `> >' within a nested template argument list"
Sometimes you want it to be >>
. Consider
boost::array<int, 1024>>2> x;
In C++03 this successfully parses and creates an array of size 256
.
It won't ever be ambiguous. This is proven by the fact that in C++0x you don't have to write a space between closing template >
s any more.
The thing is that the compilers would prefer to tokenize the input as context-independently as possible. Since C++ is not a context independent language anyway, adding just this one special case isn't going to make things particularly harder.
In the current standard, tokenization is greedy, so >>
will be processed as a single token, in the same way that a +++ b
will be parsed as a ++ + b
. This has changed and the new standard. While it requires more work from the compiler implementors, it was deemed that overall it is worth it (and some major compilers already implement that as an extension anyway).