std::meta::is_move_constructible_type, std::meta::is_trivially_move_constructible_type, std::meta::is_nothrow_move_constructible_type
| Defined in header <meta>
|
||
consteval bool is_move_constructible_type( std::meta::info r );
|
(1) | (since C++26) |
consteval bool is_trivially_move_constructible_type( std::meta::info r );
|
(2) | (since C++26) |
consteval bool is_nothrow_move_constructible_type( std::meta::info r );
|
(3) | (since C++26) |
Returns true if r represents a type T that can be constructed from an rvalue reference.
return std::is_move_constructible_v<T>;.return std::is_trivially_move_constructible_v<T>;.return std::is_nothrow_move_constructible_v<T>;.If T is not a complete type, (possibly cv-qualified) void, or an array of unknown bound, the program is ill-formed.
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 program is ill-formed.
Parameters
| r | - | a reflection value |
Return value
true if r represents a class type that can be constructed from an rvalue reference, as described above. Otherwise, false.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Notes
Types without a move constructor, but with a copy constructor that accepts const T& arguments, satisfy is_move_constructible_type.
Move constructors are usually noexcept, since otherwise they are unusable in any code that provides strong exception guarantee.
Example
#include <meta>
#include <string>
struct Ex1
{
std::string str; // member has a non-trivial but non-throwing move constructor
};
static_assert(is_move_constructible_type(^^Ex1));
static_assert(!is_trivially_move_constructible_type(^^Ex1));
static_assert(is_nothrow_move_constructible_type(^^Ex1));
struct Ex2
{
int n;
Ex2(Ex2&&) = default; // trivial and non-throwing
};
static_assert(is_move_constructible_type(^^Ex2));
static_assert(is_trivially_move_constructible_type(^^Ex2));
static_assert(is_nothrow_move_constructible_type(^^Ex2));
struct NoMove1
{
// Prevents implicit declaration of default move constructor;
// however, the class is still move-constructible because its
// copy constructor can bind to an rvalue argument.
NoMove1(const NoMove1&) {}
};
static_assert(is_move_constructible_type(^^NoMove1));
static_assert(!is_trivially_move_constructible_type(^^NoMove1));
static_assert(!is_nothrow_move_constructible_type(^^NoMove1));
struct NoMove2
{
// Not move-constructible since the lvalue reference
// can't bind to the rvalue argument
NoMove2(NoMove2&) {}
};
static_assert(!is_move_constructible_type(^^NoMove2));
static_assert(!is_trivially_move_constructible_type(^^NoMove2));
static_assert(!is_nothrow_move_constructible_type(^^NoMove2));
int main() {}
See also
(C++26) |
checks if reflected type is a non-union class type (function) |
(C++26)(C++26)(C++26)(C++26) |
checks if the reflected entity is a constructor of this kind (function) |
(C++26)(C++26)(C++26) |
checks if reflected type has a constructor for specific arguments (function template) |
| checks if reflected type has a default constructor (function) | |
| checks if reflected type has a copy constructor (function) | |
(C++20) |
specifies that an object of a type can be move constructed (concept) |
(C++11) |
converts the argument to an xvalue (function template) |
(C++11) |
converts the argument to an xvalue if the move constructor does not throw (function template) |
(C++11)(C++11)(C++11) |
checks if a type can be constructed from an rvalue reference (class template) |