最終更新日時(UTC):
が更新

履歴 編集

class template
<type_traits>

std::is_nothrow_move_assignable(C++11)

namespace std {
  template <class T>
  struct is_nothrow_move_assignable;

  template <class T>
  inline constexpr bool is_nothrow_move_assignable_v
    = is_nothrow_move_assignable<T>::value;          // C++17
}

概要

Tがムーブ代入可能で、かつ代入操作が例外を投げないかを調べる。

要件

Tは完全型であるか、const/volatile修飾された(あるいはされていない)voidか、要素数不明の配列型でなければならない。

効果

is_nothrow_move_assignableは、型Tが例外を投げない保証のもとにムーブ代入可能であるならばtrue_typeから派生し、そうでなければfalse_typeから派生する。

以下の条件がtrueである場合に、例外を投げないムーブ代入が可能であると見なされる:

  • C++11 : is_nothrow_assignable<T&, T&&>::value == true
  • C++14 : 参照可能な型Tに対しては、is_nothrow_assignable<T&, T&&>::value == trueと同じ結果となり、それ以外はfalseと見なされる。
    • 参照可能な型とは、以下のいずれかの条件に合致する型である:
      • オブジェクト型
      • CV修飾されていない、もしくは参照修飾されていない関数型
      • 参照修飾されている型

#include <type_traits>

// nothrow move assignable
struct A {};

// nothrow move assignable
struct B {
  B& operator=(B&&) noexcept
  { return *this; }
};

// not move assignable
struct C {
  C& operator=(C&&)
  { return *this; }
};

// not nothrow move assignable
struct D {
  D& operator=(D&&) noexcept(false)
  { return *this; }
};

static_assert(
  std::is_nothrow_move_assignable<int>::value == true,
  "int is nothrow move assignable");

static_assert(
  std::is_nothrow_move_assignable<A>::value == true,
  "A is nothrow move assignable");

static_assert(
  std::is_nothrow_move_assignable<B>::value == true,
  "B is nothrow move assignable");

static_assert(
  std::is_nothrow_move_assignable<C>::value == false,
  "C is not nothrow move assignable");

static_assert(
  std::is_nothrow_move_assignable<D>::value == false,
  "D is not nothrow move assignable");

int main() {}

出力

バージョン

言語

  • C++11

処理系

  • Clang: 3.0
  • GCC: 4.7.3
  • Visual C++: 2012, 2013, 2015
    • 2012~2013には、提案時の名前であるhas_nothrow_move_assignも存在する。
    • 2012は、intなどの組込型において、誤ってfalse_typeになっている。

参照