Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "vector<pair<int,int>> q;" and "vector<pair<int,int> > q;" [duplicate]

Tags:

c++

vector

I get compile error with the former but latter works just fine.

error: ‘>>’ should be ‘> >’ within a nested template argument list

Thanks

like image 527
Udit Bhutani Avatar asked Dec 10 '22 20:12

Udit Bhutani


1 Answers

In the (now obsolete) revisions C++98 and C++03, the character sequence ">>" was unconditionally interpreted as the "right shift operator" token, so if you wanted to close multiple template argument lists, you would need to leave some intervening whitespace.

As of C++11, the lexical rules of the language have been modified to interpret ">>" as two consecutive template argument list ends, and the whitespace is no longer necessary. (However, this makes it necessary to parenthesize shift expressions in a template argument list.)

(In the same wash, C++11 also interprets <::foo, when used as the first template argument, in the "obvious" way (beginning of argument list, followed by namespace qualifier) rather than consuming <: as the alternative token for [.)

like image 126
Kerrek SB Avatar answered Dec 13 '22 09:12

Kerrek SB