Thread overview
Derived classes? Reflection
Apr 13, 2013
Tofu Ninja
Apr 13, 2013
Andrej Mitrovic
Apr 13, 2013
Namespace
Apr 13, 2013
Tofu Ninja
Apr 13, 2013
Tofu Ninja
Apr 14, 2013
Benjamin Thaut
Mar 29, 2019
Alex
April 13, 2013
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
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
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
> 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
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
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
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).