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 if T is move-assignable, false otherwise(公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
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> {}; |
[編集] 注釈
The trait std::is_move_assignable is less strict than MoveAssignable because it does not check the type of the result of the assignment (which, for a MoveAssignable type, must be T&), nor the semantic requirement that the target's value after the assignment is equivalent to the source's value before the assignment.
The type does not have to implement a move assignment operator in order to satisfy this trait; see MoveAssignable for details.
[編集] 例
#include <iostream> #include <string> #include <type_traits> struct Foo { int n; }; struct NoMove { // prevents implicit declaration of default move assignment operator // however, the class is still move-assignable because its // copy assignment operator can bind to an rvalue argument 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 | the behavior was unclear if T&& cannot be formed | この場合、生成される値はfalseである |
[編集] 関連項目
| (C++11)(C++11)(C++11) |
型が特定の引数に対する代入演算子を持つかをチェックする (クラステンプレート) |
| (C++11)(C++11)(C++11) |
型がコピー代入演算子を持つかをチェックする (クラステンプレート) |