Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
April 13, 2013 Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Currently is there a way to get all of the subclasses of a class at compile time? It seems like something that should be possible using traits but I can't seems to see how. Something like class A{...} class B:A{...} class C:A{...} ... foreach(auto t ; getsubclass(A)) { ... } Any help would be grateful. Tofu |
April 13, 2013 Re: Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On 4/13/13, Tofu Ninja <emmons0@purdue.edu> wrote:
> Currently is there a way to get all of the subclasses of a class at compile time?
There might be things like using .moduleinfo and traversing imports to find all classes, but I think separate compilation makes this unreliable.
There is however BaseClassTuple in std.traits, so you can pass a leaf class to get the class hierarchy.
|
April 13, 2013 Re: Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Saturday, 13 April 2013 at 16:16:03 UTC, Tofu Ninja wrote: > Currently is there a way to get all of the subclasses of a class at compile time? > It seems like something that should be possible using traits but I can't seems to see how. > > Something like > > class A{...} > class B:A{...} > class C:A{...} > > ... > > foreach(auto t ; getsubclass(A)) > { > ... > } > > Any help would be grateful. > Tofu Maybe this is helpfully: http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn@forum.dlang.org |
April 13, 2013 Re: Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | > Maybe this is helpfully:
> http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn@forum.dlang.org
Oddly enough, I found that at about the same time you posted it.
|
April 13, 2013 Re: Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Saturday, 13 April 2013 at 17:45:12 UTC, Tofu Ninja wrote:
>> Maybe this is helpfully:
>> http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn@forum.dlang.org
>
> Oddly enough, I found that at about the same time you posted it.
Sadly this does not provide a compile time solution, only runtime.
|
April 14, 2013 Re: Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | Am 13.04.2013 19:49, schrieb Tofu Ninja:
> On Saturday, 13 April 2013 at 17:45:12 UTC, Tofu Ninja wrote:
>>> Maybe this is helpfully:
>>> http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn@forum.dlang.org
>>
>> Oddly enough, I found that at about the same time you posted it.
>
> Sadly this does not provide a compile time solution, only runtime.
Do you need all derived classes or or only all derived classes within one module? Because the former is most likely impossible because it would break the compilation model.
Kind Regards
Benjamin Thaut
|
March 29, 2019 Re: Derived classes? Reflection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Saturday, 13 April 2013 at 17:50:00 UTC, Tofu Ninja wrote:
> On Saturday, 13 April 2013 at 17:45:12 UTC, Tofu Ninja wrote:
>>> Maybe this is helpfully:
>>> http://forum.dlang.org/thread/scgjnudclnwlbdqqdsyn@forum.dlang.org
>>
>> Oddly enough, I found that at about the same time you posted it.
>
> Sadly this does not provide a compile time solution, only runtime.
I wonder if one could use this to first spawn a process at compile type and then spit out the information and then process that info at compile time(say from a text file).
|
Copyright © 1999-2021 by the D Language Foundation