Namespaces
Variants
Standard revision:
Views
Actions

Angle Bracket hack

From cppreference.com
< cpp‎ | language


The angle bracket hack resolves a lexing ambiguity when a templated name ending in ">" is used as the template parameter of another class template or function template. Prior to C++11, when two consecutive angle brackets appeared, many lexers would interpret these as the right shift operator instead according to the language grammar. As a workaround, a space would need to be inserted between the two angle brackets so a lexer could interpret them as individual angle bracket tokens.

template <typename T>
struct A
{
    A(){}
};
 
template <typename T>
struct B
{
    B(){}
};
 
 
int main()
{
	A<B<int> > c; // space between >'s needed on many compilers prior to C++11
	A<B<int>> d;  // ok on C++11 and above
}