显示声明析构函数
A move operation is not implicitly generated for a class where the user has explicitly declared a destructor. Furthermore, the generation of copy operations is deprecated in this case (§44.2.3). This can be a good reason to explicitly define a destructor even where the compiler would have implicitly provided one (§17.2.3).
显示声明析构函数,就不会隐式生成默认拷贝/移动构造函数,即使编译器能隐式生成析构函数,我们也是最好显示声明析构函数。
lambda表达式 (隐式函数对象)
[&](int a){ return a<x; } 类似于 func_object_name fon{x}
[]:不捕获任何变量
[&]:以引用的方式捕获
[=]:以拷贝值的方式捕获
[&x]:以引用的方式只捕获x变量
- 隐式生成函数对象
void f(const Vector<int>& vec, const list<string>& lst, int x, const string& s)
{
cout << "number of values less than " << x
<< ": " << count(vec,[&](int a){ return a<x; }) << '\n';
cout << "number of values less than " << s
<< ": " << count(lst,[&](const string& a){ return a<s; }) << '\n';
}
可变参数模板
谨记:把第一个参数和其他参数区分对待
template<typename T, typename... Tail>
void f(T head, Tail... tail)
{
g(head); // do something to head
f(tail...); // try again with tail
}
void f() { } // do nothing
语句作用域
for while if switch的 ()中声明的变量
auto的时候不能使用列表初始化
auto z1 {99}; // z1 is an initializer_list
auto z2 = 99; // z2 is an int