std::meta::is_aggregate_type
From cppreference.com
| Defined in header <meta>
|
||
consteval bool is_aggregate_type( std::meta::info r );
|
(since C++26) | |
Returns true if r represents an aggregate type. Otherwise returns false.
Parameters
| r | - | a reflection value |
Return value
true if r represents an aggregate type; otherwise false.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Example
Run this code
#include <meta>
#include <string>
// Check what types are aggregates.
static_assert(is_aggregate_type(^^int[1]), "an array is an aggregate");
static_assert(!is_aggregate_type(^^std::string));
static_assert(is_aggregate_type(^^std::string[1]));
struct A
{
std::string s{'A'}; // OK: default member initializers are allowed
inline static int y{1}; // OK: public static members are allowed
void f2() {} // OK: public non-static functions are allowed
static void f1() {} // OK: public static functions are allowed
~A() {} // OK: non-virtual destructors are allowed
private:
inline static int z{1}; // OK: private/protected static members are allowed
static void f3() {} // OK: private/protected static functions are allowed
void f4() {} // OK: private/protected non-static functions are allowed
};
static_assert(is_aggregate_type(^^A));
class B
{
int y{1}; // Error: private/protected non-static data members are disallowed
};
static_assert(!is_aggregate_type(^^B));
struct C : public A {}; // OK
static_assert(is_aggregate_type(^^C), "public inheritance is allowed");
struct D : protected A {};
static_assert(!is_aggregate_type(^^D), "protected/private inheritance is disallowed");
struct E : virtual A {};
static_assert(!is_aggregate_type(^^E), "virtual base classes are disallowed");
struct F { virtual void foo() {} };
static_assert(!is_aggregate_type(^^F), "virtual functions are disallowed");
struct G { G() {} };
static_assert(!is_aggregate_type(^^G), "user-declared constructors are disallowed");
enum class H { e };
static_assert(!is_aggregate_type(^^H), "enumerations are not aggregate");
int main() {}
