Namespaces
Variants

std::meta::is_empty_type

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool is_empty_type( std::meta::info r );
(since C++26)

Returns true if r represents a class (but not union) type and has no non-static data members. Otherwise returns false.

Parameters

r - a reflection value

Return value

true if r represents an empty class type; otherwise false.

Exceptions

Throws std::meta::exception if r does not represent a type or type alias.

Example

#include <meta>
#include <print>

struct A {};
static_assert(is_empty_type(^^A));

struct B { int m; };
static_assert(!is_empty_type(^^B));

struct C { static int m; };
static_assert(is_empty_type(^^C));

struct D { virtual ~D(); };
static_assert(!is_empty_type(^^D));

union E {};
static_assert(!is_empty_type(^^E));

struct F
{
    int: 0;
    // C++ standard allows "an unnamed bit-field with a width of zero
    // specifies alignment of the next bit-field at an allocation unit boundary.
    // Only when declaring an unnamed bit-field may the width be zero."
};
static_assert(is_empty_type(^^F)); // holds only unnamed bit-fields of zero width

struct G { [[no_unique_address]] E e; };

int main()
{
    std::println("G: {}", is_empty_type(^^G)); // the result is ABI-dependent
}

Possible output:

G: true

See also

(C++11)
checks if a type is a class (but not union) type and has no non-static data members
(class template) [edit]
checks if reflected type is a non-union class type
(function) [edit]
checks if reflected type is a union type
(function) [edit]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.