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

履歴 編集

class template
<type_traits>

std::is_nothrow_assignable(C++11)

namespace std {
  template <class T, class U>
  struct is_nothrow_assignable;

  template <class T, class U>
  inline constexpr bool is_nothrow_assignable_v
    = is_nothrow_assignable<T, U>::value; // C++17
}

概要

Tが型Uから代入可能で、かつ代入操作が例外を投げないかを調べる。

要件

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

効果

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

is_assignable<T, U>::value == trueかつ、いかなる例外を投げないならば、例外を投げない代入が可能であると判断される。

#include <type_traits>

struct X {
  X& operator=(const X&) noexcept
  { return *this; }

  X& operator=(X&&) noexcept
  { return *this; }
};

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

static_assert(
  std::is_nothrow_assignable<X&, const X&>::value == true,
  "X is nothrow copy assignable");

static_assert(
  std::is_nothrow_assignable<X&, X&&>::value == true,
  "X is nothrow move assignable");

int main() {}

出力

バージョン

言語

  • C++11

処理系

参照