4

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

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

Thanks

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Udit Bhutani
  • 127
  • 1
  • 6
  • The difference is a white-space, obviously. The error message is pretty clear, isn't it? – Uwe Keim Oct 17 '15 at 10:04
  • 4
    Older versions of C++ required a space between `>`s in nested templates. I think this ugliness has been fixed in more modern versions of the standard, though. – Sergey Kalinichenko Oct 17 '15 at 10:04
  • @UweKeim: Given the nature of the ambiguity and the notorious quality of C++ template compiler diagnostics, I'd actually be surprised if the error were anywhere near "clear". – Kerrek SB Oct 17 '15 at 10:11

2 Answers2

9

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 [.)

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
4

Before C++11, you had to use whitespace to separate the angle brackets in nested templates - otherwise the compiler was interpreting it as right-shift operator ">>". In C++11, you can ommit the whitespace and it will be interpreted as brackets.

However some compilers (eg. MSVC++) ignore the standard and allow you to ommit the whitespace even when not using C++11 standard.

yaqwsx
  • 569
  • 1
  • 5
  • 14