mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 21:22:20 +03:00
Fix Bugzilla issue 24875 (#9090)
This makes it so that enums whose base type is an aggregate type are also considered an aggregate type. It probably doesn't affect much code, since isAggregateType isn't needed often, and it's fairly rare to declare enums whose base type is an aggregate type, but in general, code that cares whether a type is an aggregate type is going to care that an enum's base type is an aggregate type.
This commit is contained in:
parent
43f00ee83d
commit
aee681c468
1 changed files with 21 additions and 6 deletions
27
std/traits.d
27
std/traits.d
|
@ -7251,16 +7251,21 @@ alias PointerTarget(T : T*) = T;
|
|||
/**
|
||||
* Detect whether type `T` is an aggregate type.
|
||||
*/
|
||||
enum bool isAggregateType(T) = is(T == struct) || is(T == union) ||
|
||||
is(T == class) || is(T == interface);
|
||||
template isAggregateType(T)
|
||||
{
|
||||
static if (is(T == enum))
|
||||
enum isAggregateType = isAggregateType!(OriginalType!T);
|
||||
else
|
||||
enum isAggregateType = is(T == struct) || is(T == class) || is(T == interface) || is(T == union);
|
||||
}
|
||||
|
||||
///
|
||||
@safe unittest
|
||||
{
|
||||
class C;
|
||||
union U;
|
||||
struct S;
|
||||
interface I;
|
||||
class C {}
|
||||
union U {}
|
||||
struct S {}
|
||||
interface I {}
|
||||
|
||||
static assert( isAggregateType!C);
|
||||
static assert( isAggregateType!U);
|
||||
|
@ -7271,6 +7276,16 @@ enum bool isAggregateType(T) = is(T == struct) || is(T == union) ||
|
|||
static assert(!isAggregateType!(int[]));
|
||||
static assert(!isAggregateType!(C[string]));
|
||||
static assert(!isAggregateType!(void delegate(int)));
|
||||
|
||||
enum ES : S { a = S.init }
|
||||
enum EC : C { a = C.init }
|
||||
enum EI : I { a = I.init }
|
||||
enum EU : U { a = U.init }
|
||||
|
||||
static assert( isAggregateType!ES);
|
||||
static assert( isAggregateType!EC);
|
||||
static assert( isAggregateType!EI);
|
||||
static assert( isAggregateType!EU);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue