c++11特性

1767 ワード

  • lambda特性
  • カッコ初期化リストstd::initializer_list
  • エージェント構築関数
  • 文字列字面増分
  • ユーザ定義字面量
  • #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 << '
    '; std::cout << 1.0_m << '
    '; std::cout << 1.0_km << '
    '; }
  • 右値参照とmove意味
  • 一時変数
  • をより効率的に使用するために.
    MyString(MyString && str){
        std::cout<
  • 強タイプ列挙
  • 可変パラメータテンプレートおよびパッケージ
  • 
    #include
    using namespace std;
    template
    void f(T ... args){
        cout<

    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.