2011-11-25 CPlusPlus0X

Getting multiple angle brackets right

A mostly embarrassing thing with good old C++ was that multiple right angle brackets ">>" was defined as the right shift operator, period! So with nested template definition you loose and had to insert extra spaces to make the parser behave. So this was what you had to write to define a list of lists of integers:

list<list<int> > listOfListOfIntegers;

See the extra space there? Could it be interpreted as a right shift? Hardly.

C++11 fixes this by allowing multiple right angle brackets as closing template delimiters where it can't be confused with the right shift operator. So we can now write this:

list<list<int>> listOfListOfIntegers;

Feels right doesn't it!

Note that the old notation is of course still valid. You can have spaces between the closing delimiters. So this does not break old code.