Any way to tell if an object is inside another class?

Mike Parker aldacron at
Mon Sep 28 14:36:01 UTC 2020

On Monday, 28 September 2020 at 14:23:12 UTC, Ruby The Roobster 
> On Monday, 28 September 2020 at 14:22:34 UTC, Ruby The Roobster 
> wrote:
>> I meant User Defined types. not UDAs. Anyways, the whole thing 
>> is me trying to find a hacky workaround that allows something 
>> similar to multiple alias this declarations(because multiple 
>> of these are not possible). And for this, I have to determine 
>> if a normal number is being passed, or if an user defined type 
>> is being passed through the parameter.
> I mean type, not number

There's the `parent` trait. You can wrap it like this:

import std;
class Foo {
     int x;
struct Bar {
     Foo f;
Foo g;

enum hasParent(alias sym) = is(__traits(parent, sym) == class) || 
is(__traits(parent, sym) == struct);

void main() {
    writeln(hasParent!(Bar.f));   // true

More information about the Digitalmars-d-learn mailing list