I am currently reviewing the new features of C ++ 11 and for some unknown reason, some of them do not compile. I am using gcc version 4.6.0 20100703 (experimental) (GCC), so according to the GNU GCC FAQ, all the functions I tried are supported . I tried to compile both flags std = C ++ 0x and std = gnu ++ 0x.
Non member begin () and end ()
For example, I will not use non member begin () and end () in a piece of code, for example:
#include <iostream> #include <map> #include <utility> #include <iterator> using namespace std; int main ( ) { map < string, string > alias; alias.insert ( pair < string, string > ( "ll", "ls -al" ) ); // ... Other inserts auto it = begin(alias); while ( it != end(alias) ) { //... }
And I get
nonMemberBeginEnd//main.cc:15:24: error: 'begin' was not declared in this scope nonMemberBeginEnd//main.cc:15:24: error: unable to deduce 'auto' from '<expression error>' // Ok, this one is normal. nonMemberBeginEnd//main.cc:16:26: error: 'end' was not declared in this scope
Should special headers be included?
For range
My second (and last) question is stranger, because it cannot depend on the hidden title of black magic, which I may not have included.
The following code:
for ( auto kv : alias ) cout << kv.first << " ~ " << kv.second << endl;
Give me the following errors:
rangeFor/main.cc:15:17: error: expected initializer before ':' token
I hope my questions are off topic or too new for you, and you will help me find out what is wrong: D
source share