std:: is_move_assignable, std:: is_trivially_move_assignable, std:: is_nothrow_move_assignable
|
ヘッダーで定義
<type_traits>
|
||
|
template
<
class
T
>
struct is_move_assignable ; |
(1) | (C++11以降) |
|
template
<
class
T
>
struct is_trivially_move_assignable ; |
(2) | (C++11以降) |
|
template
<
class
T
>
struct is_nothrow_move_assignable ; |
(3) | (C++11以降) |
| 型特性 |
メンバ定数
value
の値
|
|
|---|---|---|
T
が
参照可能な型
の場合
|
T
が参照可能な型でない場合
|
|
| (1) | std:: is_assignable < T & , T && > :: value | false |
| (2) | std:: is_trivially_assignable < T & , T && > :: value | |
| (3) | std:: is_nothrow_assignable < T & , T && > :: value | |
T
が完全型でない場合、(おそらくcv修飾された)
void
または不明な境界の配列である場合、動作は未定義です。
上記のテンプレートのインスタンス化が、直接的または間接的に不完全型に依存しており、その型が仮に完全化された場合に異なる結果をもたらす可能性がある場合、その動作は未定義です。
プログラムがこのページで説明されているテンプレートのいずれかに対して特殊化を追加する場合、動作は未定義です。
目次 |
ヘルパー変数テンプレート
|
template
<
class
T
>
inline
constexpr
bool
is_move_assignable_v
=
|
(C++17以降) | |
|
template
<
class
T
>
inline
constexpr
bool
is_trivially_move_assignable_v
=
|
(C++17以降) | |
|
template
<
class
T
>
inline
constexpr
bool
is_nothrow_move_assignable_v
=
|
(C++17以降) | |
std::integral_constantから継承
メンバ定数
|
value
[static]
|
true
Tがムーブ代入可能な場合は
false
それ以外の場合
(公開静的メンバ定数) |
メンバ関数
|
operator bool
|
オブジェクトを
bool
に変換し、
value
を返す
(公開メンバ関数) |
|
operator()
(C++14)
|
value
を返す
(公開メンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
実装例
template<class T> struct is_move_assignable : std::is_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type> {}; template<class T> struct is_trivially_move_assignable : std::is_trivially_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type> {}; template<class T> struct is_nothrow_move_assignable : std::is_nothrow_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type> {}; |
注記
特性
std::is_move_assignable
は
MoveAssignable
よりも厳密さが低い。なぜなら、代入演算の結果の型(
MoveAssignable
型の場合
T&
でなければならない)や、代入後のターゲットの値が代入前のソースの値と等価であるという意味要件をチェックしないためである。
この特性を満たすために型が move assignment operator を実装する必要はありません。詳細については MoveAssignable を参照してください。
例
#include <iostream> #include <string> #include <type_traits> struct Foo { int n; }; struct NoMove { // デフォルトのムーブ代入演算子の暗黙的な宣言を防止する // ただし、コピー代入演算子が右辺値引数にバインドできるため、 // このクラスは依然としてムーブ代入可能である NoMove& operator=(const NoMove&) { return *this; } }; int main() { std::cout << std::boolalpha << "std::string is nothrow move-assignable? " << std::is_nothrow_move_assignable<std::string>::value << '\n' << "int[2] is move-assignable? " << std::is_move_assignable<int[2]>::value << '\n' << "Foo is trivially move-assignable? " << std::is_trivially_move_assignable<Foo>::value << '\n' << "NoMove is move-assignable? " << std::is_move_assignable<NoMove>::value << '\n' << "NoMove is nothrow move-assignable? " << std::is_nothrow_move_assignable<NoMove>::value << '\n'; }
出力:
std::string is nothrow move-assignable? true int[2] is move-assignable? false Foo is trivially move-assignable? true NoMove is move-assignable? true NoMove is nothrow move-assignable? false
欠陥報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2196 | C++11 | T && が形成できない場合の動作が不明確であった | この場合に生成される値は false である |
関連項目
|
(C++11)
(C++11)
(C++11)
|
型が特定の引数に対する代入演算子を持つかどうかをチェックする
(クラステンプレート) |
|
(C++11)
(C++11)
(C++11)
|
型がコピー代入演算子を持つかどうかをチェックする
(クラステンプレート) |