c++ 11 特性

  1. lambda特性
  2. 括号初始化列表 std::initializer_list
  3. 代理构造函数
  4. 字符串字面增量
  5. 用户定义 字面量
#include 

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';
}
  1. 右值引用和move语义
  • 为了更加高效的使用临时变量
MyString(MyString && str){
    std::cout<<"Move Constructor is called: source: "<
  1. 强类型枚举
  1. 可变参数模板和打包

#include
using namespace std;
template
void f(T ... args){
    cout<

Parameter pack

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

你可能感兴趣的:(c++ 11 特性)