Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 05, 2016 Getting the superclass of a type? | ||||
---|---|---|---|---|
| ||||
I'd like to be able to write something like this, but I haven't been able to find anything in the docs class Base{} class Sub: Base{} static assert(is(SuperClassOf!Sub == Base)); |
September 05, 2016 Re: Getting the superclass of a type? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | On Monday, 5 September 2016 at 15:20:10 UTC, pineapple wrote: > I'd like to be able to write something like this, but I haven't been able to find anything in the docs > > class Base{} > class Sub: Base{} > static assert(is(SuperClassOf!Sub == Base)); https://dlang.org/phobos/std_traits.html#.BaseClassesTuple |
September 05, 2016 Re: Getting the superclass of a type? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lodovico Giaretta | Am 05.09.2016 um 17:43 schrieb Lodovico Giaretta: > On Monday, 5 September 2016 at 15:20:10 UTC, pineapple wrote: >> I'd like to be able to write something like this, but I haven't been able to find anything in the docs >> >> class Base{} >> class Sub: Base{} >> static assert(is(SuperClassOf!Sub == Base)); > > https://dlang.org/phobos/std_traits.html#.BaseClassesTuple Another option would be to use the following: class Base {} class Sub: Base {} class Other {} static assert(is(Sub : Base)); static assert(!is(Other : Base)); However, the ":" syntax also works for automatic conversion (see http://ddili.org/ders/d.en/is_expr.html and search for "is (T : OtherT)"). |
September 05, 2016 Re: Getting the superclass of a type? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lodovico Giaretta | On Monday, 5 September 2016 at 15:43:52 UTC, Lodovico Giaretta wrote:
> On Monday, 5 September 2016 at 15:20:10 UTC, pineapple wrote:
>> I'd like to be able to write something like this, but I haven't been able to find anything in the docs
>>
>> class Base{}
>> class Sub: Base{}
>> static assert(is(SuperClassOf!Sub == Base));
>
> https://dlang.org/phobos/std_traits.html#.BaseClassesTuple
Aha, thank you!
|
Copyright © 1999-2021 by the D Language Foundation