Namespaces
Variants

std::meta::is_constructible_type, std::meta::is_trivially_constructible_type, std::meta::is_nothrow_constructible_type

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_constructible_type( std::meta::info r, Args&& args );
(1) (since C++26)
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_trivially_constructible_type( std::meta::info r, Args&& args );
(2) (since C++26)
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_nothrow_constructible_type( std::meta::info r, Args&& args );
(3) (since C++26)

Returns true if r represents a type T that is constructible, trivially constructible or non-throwing constructible, respectively, from the range args of reflected types or type aliases.

Let ARGS... be a pack of types or type aliases whose elements are represented by the corresponding elements of args.

1) Equivalent to return std::is_constructible_v<T, ARGS...>;.
2) Equivalent to return std::is_trivially_constructible_v<T, ARGS...>;.
3) Equivalent to return std::is_nothrow_constructible_v<T, ARGS...>;.

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.

Template parameters

Args - range type that contains reflected types

Parameters

r - a reflection value to test
args - a range of reflected argument types

Return value

true if r represents a type that is:

1) constructible,
2) trivially constructible or
3) non-throwing constructible,

from args as described above. Otherwise, false.

Exceptions

Throws std::meta::exception:

  • If either r or any element of args does not represent a type or type alias.
  • If T or any type in the pack ARGS... is not a complete type, (possibly cv-qualified) void, or an array of unknown bound.
  • If an instantiation of a template (1-3) depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed.

Example

#include <meta>

class C
{
    int v1;
    double v2;
public:
    C(int n) : v1(n), v2() {}
    C(int n, double f) noexcept : v1(n), v2(f) {}
};

static_assert
(""
    &&   is_trivially_constructible_type(^^C, {^^const C&})
    && ! is_trivially_constructible_type(^^C, {^^int})
    &&   is_constructible_type(^^C, {^^int})
    && ! is_nothrow_constructible_type(^^C, {^^int})
    &&   is_nothrow_constructible_type(^^C, {^^int, ^^double})
);

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 default constructor
(function) [edit]
checks if reflected type has a copy constructor
(function) [edit]
checks if reflected type can be constructed from an rvalue reference
(function) [edit]
specifies that a variable of the type can be constructed from or bound to a set of argument types
(concept) [edit]
checks if a type has a constructor for specific arguments
(class template) [edit]