std::is_mov...assignable,(3)
π NAME π
Okay bestie, welcome to the std::is_mov...assignable,(3) page from the C++ Standard Library manual β the one all about move-assignability type traits. It covers std::is_move_assignable, std::is_trivially_move_assignable, and std::is_nothrow_move_assignable. No cap, these are the vibe-checkers for βcan I move-assign this type?β π
β¨ Synopsis β¨
Defined in header <type_traits>:
template< class T > (1) (since C++11)
struct is_move_assignable;
template< class T > (2) (since C++11)
struct is_trivially_move_assignable;
template< class T > (3) (since C++11)
struct is_nothrow_move_assignable;
Hereβs the value table, bestie: the T is a referenceable type column gives the trait expression below, and the T is not a referenceable type column is false (the extracted text shows false on the (2) row). Table translation era π
(1)βstd::is_assignable<T, T&&>::value(2)βstd::is_trivially_assignable<T, T&&>::value(3)βstd::is_nothrow_assignable<T, T&&>::value
Behavior undefined alert π¨ IfTis not a complete type,(possibly cv-qualified) void, or an array of unknown bound, the behavior is undefined.
Another UB warning π If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed, the behavior is undefined.
Specialization warning π If the program adds specializations for any of the templates described on this page, the behavior is undefined.
π«Ά Member constants π«Ά
valueβtrueifTis move-assignable,falseotherwise. Itβs[static]β public static member constant. Iconic little boolean.
πΈ Member functions πΈ
operator boolβ converts the object tobool, returnsvalue(public member function).operator()β returnsvalue(C++14) (public member function).
π Member types π
value_typeβbooltypeβstd::integral_constant<bool, value>
π§ Possible implementation π§
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> {};
π₯ Notes π₯
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.
π Example π
// Run this code
#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';
}
π Output: π
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
π See also π
is_assignable(C++11),is_trivially_assignable(C++11),is_nothrow_assignable(C++11) β checks if a type has an assignment operator for a specific argument (class template).is_copy_assignable(C++11),is_trivially_copy_assignable(C++11),is_nothrow_copy_assignable(C++11) β checks if a type has a copy assignment operator (class template).
Source/version/date energy: http://cppreference.com, 2024.06.10, page std::is_mov...assignable,(3). Thatβs the whole manual page, bestie β go move-assign something responsibly! πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms