std::meta::is_assignable_type, std::meta::is_trivially_assignable_type, std::meta::is_nothrow_assignable_type - cppreference.com
Namespaces
Variants

std::meta::is_assignable_type, std::meta::is_trivially_assignable_type, std::meta::is_nothrow_assignable_type

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool is_assignable_type( std::meta::info type_dst,
                                   std::meta::info type_src );
(1) (since C++26)
consteval bool is_trivially_assignable_type( std::meta::info type_dst,
                                             std::meta::info type_src );
(2) (since C++26)
consteval bool is_nothrow_assignable_type( std::meta::info type_dst,
                                           std::meta::info type_src );
(3) (since C++26)

Returns true if type_dst and type_src represent types T and U respectively such that U can be assigned to T, i.e., T has an appropriate assignment operator for argument of type U.

1) Equivalent to return std::is_assignable_type_v<T, U>;.
2) Equivalent to return std::is_trivially_assignable_v<T, U>;.
3) Equivalent to return std::is_nothrow_assignable_v<T, U>;.

If either T or U 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

type_dst - a reflection value to be used as a destination
type_src - a reflection value to be used as a source

Return value

true if U can be assigned to T, as described above. Otherwise, false.

Exceptions

Throws std::meta::exception if any of type_dst or type_src does not represent a type or type alias.

Notes

This meta function does not check anything outside the immediate context of the assignment expression: if the use of T or U would trigger template specializations, generation of implicitly-defined special member functions etc, and those have errors, the actual assignment may not compile even if std::is_assignable_v<T, U> compiles and evaluates to true.

Example

#include <meta>
#include <string>

struct C { int n; };

static_assert(""
    && is_assignable_type(^^int, ^^int) == false // Error, 1 = 1 won't compile
    && is_assignable_type(^^int&, ^^int) == true // OK, int a; a = 1;
    && is_assignable_type(^^int, ^^double) == false // Error, 1 = 1.0;
    && is_nothrow_assignable_type(^^int&, ^^double) == true // OK, int a; a = 1.0;
    // uses implicit conversion double -> char, then string::operator=(char)
    && is_assignable_type(^^std::string, ^^double) == true // OK, s = 99.6; 'c' == s
    && is_trivially_assignable_type(^^C&, ^^const C&) == true
);

int main() {}

See also