6

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?

relaxxx
  • 6,646
  • 7
  • 34
  • 63

4 Answers4

6

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

Prasoon Saurav
  • 85,400
  • 43
  • 231
  • 337
6

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;
CB Bailey
  • 648,528
  • 94
  • 608
  • 638
4

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

Nawaz
  • 327,095
  • 105
  • 629
  • 812
  • 2
    Actually, it's not allowed for a conforming C++03 compiler to implement C++0x semantics for `>>`. There are valid C++03 constructs which can break with this change. – CB Bailey Apr 24 '11 at 15:07
  • @Charles: Interesting. But I would like to know what valid C++03 constructs can be broken with this change, and how C++0x handles this then? – Nawaz Apr 24 '11 at 15:10
  • @Nawaz: E.g. shift expressions in constant expressions for non-type template parameters. E.g. `tmpl< tmpl<2 >> 1> > instance;`. Usually valid C++03 becomes a compile error in C++0x. I haven't managed to construct any situation where this causes a silent change in behaviour. – CB Bailey Apr 24 '11 at 15:14
  • @Charles: How does C++0x handle this then? Is it going to interpret `>>` in `<2 >> 1>` as shift operator? – Nawaz Apr 24 '11 at 15:22
  • @Nawaz: As I indicated, it's a compile error. `>>` closes the template, leaving a non-sensical `1> > instance;` token sequence where a declarator is needed. – CB Bailey Apr 24 '11 at 15:36
  • @Charles: In other words, I can say that few valid C++03 things are invalid in C++0x, right? – Nawaz Apr 24 '11 at 15:51
  • @Nawaz: I'm not 100% sure I know what you are driving. Are you looking to make a wider generalisation? There are **a** few things that are valid C++03 and aren't valid C++0x. Not least there are several more keywords that can no long be used as ordinary identifiers. – CB Bailey Apr 24 '11 at 15:58
  • @Charles: *Are you looking to make a wider generalisation?*... what does it mean? Are we discussing some philosophy? :-/ – Nawaz Apr 24 '11 at 16:16
  • @Nawaz: You said "I can say that few valid C++03 things are invalid in C++0x, right?", my thoughts were that you could say that but we really only touched on one corner case and there a probable many others. – CB Bailey Apr 24 '11 at 16:25
3

C++0x now supports that syntax without errors. Compilers have already started to implement most of these features, so it wouldn't be surprising that the latest Microsoft C++ compiler supports it.

Joseph Lisee
  • 3,247
  • 24
  • 21