- lambda特性
- 括号初始化列表 std::initializer_list
- 代理构造函数
- 字符串字面增量
- 用户定义 字面量
#include <iostream>
long double operator"" _mm(long double x) { return x / 1000; }
long double operator"" _m(long double x) { return x; }
long double operator"" _km(long double x) { return x * 1000; }
int main()
{
std::cout << 1.0_mm << '\n';
std::cout << 1.0_m << '\n';
std::cout << 1.0_km << '\n';
}
- 右值引用和move语义
- 为了更加高效的使用临时变量
MyString(MyString && str){
std::cout<<"Move Constructor is called: source: "<<str._data<<std::endl;
_len=str._len;
_data=str._data;
str._len=0;
str._data=NULL;
}
- 强类型枚举
- 可变参数模板和打包
#include<iostream>
using namespace std;
template<class ... T>
void f(T ... args){
cout<<sizeof... (args)<<endl; // 打印可变参数的个数
}
int main(){
f();
f(1,3);
f(2,3.5,"");
}
Parameter pack
- constexpr specifier
evaluate the value of the function or variable at compile time.
A constexpr variable must satisfy the following requirements:
its type must be a LiteralType
.
it must be immediately initialized
the full-expression of its initialization, including all implicit conversions, constructors calls, etc, must be a constant expression
A constexpr function must satisfy the following requirements:
it must not be virtual
its return type must be LiteralType
each of its parameters must be LiteralType
there exists at least one set of argument values such that an invocation of the function could be an evaluated subexpression of a core constant expression (for constructors, use in a constant initializer is sufficient) (since C++14). No diagnostic is required for a violation of this bullet.