On Monday, 28 September 2020 at 11:11:13 UTC, Ruby The Roobster wrote:
For example:

class test {}
class T {
auto c = new test();
}

Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in general. Why am I asking this? Because I need it to develop this Multiple Alias This project I am working on(basically just mashing all the functions into a class and then using the class with alias this)

You can use FieldTypeTuple!T to get a compile time sequence of T's field types, then use anySatisfy to check whether the field types contain the type you want:

import std.traits : FieldTypeTuple;
import std.meta : anySatisfy;

template typeEquals(T) {
    enum typeEquals(U) = is(T == U);
}

enum hasFieldOfType(Obj, Type) = anySatisfy!(
    typeEquals!Type,
    FieldTypeTuple!Obj
);

pragma(msg, hasFieldOfType!(T, int));  //false
pragma(msg, hasFieldOfType!(T, test)); //true

Reply via email to