Namespaces
Variants

std::meta::is_move_constructible_type, std::meta::is_trivially_move_constructible_type, std::meta::is_nothrow_move_constructible_type

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
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.

1) Equivalent to return std::is_move_constructible_v<T>;.
2) Equivalent to return std::is_trivially_move_constructible_v<T>;.
3) Equivalent to 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

checks if reflected type is a non-union class type
(function) [edit]
checks if the reflected entity is a constructor of this kind
(function) [edit]
checks if reflected type has a constructor for specific arguments
(function template) [edit]
checks if reflected type has a default constructor
(function) [edit]
checks if reflected type has a copy constructor
(function) [edit]
specifies that an object of a type can be move constructed
(concept) [edit]
(C++11)
converts the argument to an xvalue
(function template) [edit]
converts the argument to an xvalue if the move constructor does not throw
(function template) [edit]
checks if a type can be constructed from an rvalue reference
(class template) [edit]