Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested templates vs shift operator

I have been reading all around about be aware >> as ending of nested template and >> as shift operator...

Now I have tried it in my MSVS2010 and no problem occured.

std::map<int, std::pair<int, int>> m;

This code works exactly what I want (map of pairs) but I supposed to get some error about >>

Compiler is smarter these days?

like image 698
relaxxx Avatar asked Apr 24 '11 14:04

relaxxx


3 Answers

MSVC++2010 supports C++0x feature Right Angle Brackets

like image 169
Prasoon Saurav Avatar answered Nov 02 '22 09:11

Prasoon Saurav


Be careful because previously good C++03 code may break with compilers supporting this feature.

MyArray< MyArray<int, 16 >> 2>, 5 > arrayInst;

This would be the fix:

MyArray< MyArray<int, (16 >> 2)>, 5 > arrayInst;
like image 21
CB Bailey Avatar answered Nov 02 '22 09:11

CB Bailey


This code works exactly what I want (map of pairs) but I supposed to get some error about >>

C++0x has fixed this. So if you're not getting any error with MSVS2010, then its no wonder, as MSVS2010 has implemented some of C++0x features.

Also, even with C++03, many compilers handle such cases, though not required by the Standard(2003).

like image 31
Nawaz Avatar answered Nov 02 '22 09:11

Nawaz