Template within template: why "`>>' should be `> >' within a nested template argument list"

zw324 picture zw324 · Jul 14, 2011 · Viewed 39.1k times · Source

I know that when we are using template inside another template, we should write it like this:

vector<pair<int,int> > s;

and if we write it without the whitespace:

vector<pair<int,int>> s;

we will get an error:

`>>' should be `> >' within a nested template argument list

I see this is understandable, but I just can't help but wondering, in which cases will this be really ambiguous?

Answer

Johannes Schaub - litb picture Johannes Schaub - litb · Jul 14, 2011

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.