What Is The ‘>>’ Right-Angle Bracket Support In C++?
C++11 brings a lot of improvements over C++98. In C++98, two consecutive right-angle brackets (>>) give an error, and these constructions are treated according to the C++11 standard which means CLANG compilers no longer generate an error about right angle brackets. In this post, we explain this and how to solve the right-angle bracket problem in C++.
What is the right-angle bracket problem in C++?
Ever since the introduction of angle brackets in C++98, C++ developers have been surprised by the fact that two consecutive right-angle brackets must be separated by whitespace. For example, if you declare two-dimensional vector (int and bool) as below:
#include
typedef std::vector<std::vector<int> > vec1; // OK
typedef std::vector<std::vector<bool>> vec2; // Error |
In C++98, the first declaration is OK, but the second declaration give errors because of ‘>>‘ (right angle brackets). However, both are OK in C++11 and above.
One of the problems was an immediate consequence of the “maximum munch” principle and the fact that >> is a valid token (right shift) in C++. In the CLANG-enhanced C++ compilers, two consecutive right-angle brackets no longer generate an error, and these constructions are treated according to the C++11 standard.
This issue was a minor issue in C++98, but persisting, annoying, and somewhat embarrassing problem. The cost was reasonable, and it seems therefore worthwhile to eliminate the surprise. C++98 developers needed to add space between them. If you want to get more information, you can see details here.
How can I solve the right-angle bracket problem in C++?
If you have C++98 compiler and come across the right-angle bracket problem, you need to add space between two ‘>’ right angle brackets. ‘>>’ should be written as ‘> >’ as shown in the example below.
#include
typedef std::vector<std::vector<int> > vec2; // OK
int main() { } |
Or you should change your C++ compiler so that it supports C++11 or above. C++17 is recommended. Note that the latest RAD Studio, C++ Builder standard and CLANG compilers supports C++17 features.
What is the right-angle bracket support in C++ 11?
In the Clang-enhanced C++ compilers, two consecutive right-angle brackets no longer generate an error, and these constructions are treated according to the C++11 standard.
This example below with ‘>>’ right angle brackets can be successfully compiled with any compiler that supports C++11 and above.
#include
typedef std::vector<std::vector<int>> vec1; // OK C++11 and above
int main() { } |
For more information, see the C++11 proposal document at Right Angle Brackets Proposal document