1.那个讨厌的小空格
vector<list<int> >;// OK in each C++ version,这样的写法每个版本都支持
vector<list<int>> ;// OK since C++ 11,C++11后的版本会支持
The requirement to put a space between two closing template expressions has gone.
自从十一版本发布,要求两个相连的模板类之间必须有一个空格的要求不复存在.
主要是在文件stl_bvector.h中实现了这一改变(GNU 4.9.2中可查看).
2.nullptr
C++11 lets you use nullptr instaed of 0 or NULL to specify that a pointer refers to no value(which differs ffrom having
an undefined value).This new feature especially helps to avoid mistakes that occurred when a null pointer was interpreted as
an intergral value.
For example:
void f(int);
void f(void*);
f(0); //call f(int)
f(NULL); //call f(int) if NULL is 0,ambigous otherwise
f(nullptr); //call f(void*)
nullptr is a new keyword. It automatically converts into each pointer type but not to any
interger type.
It has type std::nullptr_t,defined in <cstddef>(since Section 5.8.1,page 161),so you can now even overload
operations for the case that a null pointer is passed.Note that std::nullptr_t counts as a fundamental data type(see Section 5.4.2,page 127).
3.auto
With C++ 11,you can declare a variable or an object without specify its specific type by using auto. For example:
auto i = 42; // i has type int
double f();
auto d = f();// d has type double
auto b; // 编译器不认识b,会编译失败,编译器无法知道这个b是什么类型
Using auto especially useful where the type is a pretty long and/or complicated expression.
For example:
[example1]
vector<string> v;
...
auto pos = v.begin;// pos has type vector<string>::iterator
[example2]
auto l = [](int x)->bool{...};//l has the type of lambda taking an int and returing a bool