std::meta::is_default_constructible_type, std::meta::is_trivially_default_constructible_type, std::meta::is_nothrow_default_constructible_type
| Defined in header <meta>
|
||
consteval bool is_default_constructible_type( std::meta::info r );
|
(1) | (since C++26) |
consteval bool is_trivially_default_constructible_type( std::meta::info r );
|
(2) | (since C++26) |
consteval bool is_nothrow_default_constructible_type( std::meta::info r );
|
(3) | (since C++26) |
Returns true if r represents a type T that is
default constructible,
trivially default constructible or
non-throwing default constructible, respectively.
return std::is_default_constructible_v<T>;.return std::is_trivially_default_constructible_v<T>;.return std::is_nothrow_default_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 type that is:
as described above. Otherwise, false.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Notes
is_default_constructible_type(^^X) does not test that X x; would compile; it attempts direct-initialization with an empty argument list (see std::meta::is_constructible_type). Thus, is_default_constructible_type(^^const int) and is_default_constructible_type(^^const int[10]) are true.
Example
#include <meta>
#include <string>
struct S1
{
std::string str; // member has a non-trivial default constructor
};
static_assert(is_default_constructible_type(^^S1));
static_assert(!is_trivially_default_constructible_type(^^S1));
struct S2
{
int n;
S2() = default; // trivial and non-throwing
};
static_assert(is_trivially_default_constructible_type(^^S2));
static_assert(is_nothrow_default_constructible_type(^^S2));
int main() {}
