C++0x ムーブコンストラクタとムーブ代入演算子を暗黙に定義

かなり前から提案は出ていましたが、N3090のWorking Draftから、
暗黙に定義される特殊メンバ関数に、ムーブコンストラクタとムーブ代入演算子が追加されることになりました。


つまり、以下のようなクラスがあった場合、

struct X {
    std::string s;
};

Xは以下のようなメンバを持つクラスになります。

struct X {
    std::string s;

    X() : s() {}                                         // デフォルトコンストラクタ
    X(const X& x) : s(x.s) {}                            // コピーコンストラクタ
    X(X&& x) : s(static_cast<std::string&&>(x.s)) {}     // ムーブコンストラクタ
        // : s(std::move(x.s)) {}
    X& operator=(const X& x) { s = x.s; return *this; }  // コピー代入演算子
    X& operator=(X&& x) {                                // ムーブ代入演算子
      s = static_cast<std::string&&>(x.s); return *this;
    }
        // { s = std::move(x.s); return *this; }
    ~X() {}                                              // デストラクタ
};

これにともない、ムーブコンストラクタとムーブ代入演算子
default/delete指定ができるようになります。

struct X {
    X(X&&) = default;
    X& operator=(X&&) = default;
};

また、type_traitsにもhas_trivial_move_constructor、has_trivial_move_assign、
has_nothrow_move_constructor、has_nothrow_move_assignが追加されます。

// 20.6.4.3, type properties:
...
template <class T> struct has_trivial_default_constructor;
template <class T> struct has_trivial_copy_constructor;
template <class T> struct has_trivial_move_constructor;
template <class T> struct has_trivial_copy_assign;
template <class T> struct has_trivial_move_assign;
template <class T> struct has_trivial_destructor;
template <class T> struct has_nothrow_default_constructor;
template <class T> struct has_nothrow_copy_constructor;
template <class T> struct has_nothrow_move_constructor;
template <class T> struct has_nothrow_copy_assign;
template <class T> struct has_nothrow_move_assign;
template <class T> struct has_virtual_destructor;
...

N3053 Defining Move Special Member Functions