I wanted to create a struct with a member function whose behavior was different depending on whether the struct instance had a particular UDA.

However, it seems like hasUDA doesn't seem to produce the result I would have expected here. I tried using getAttributes, but that didn't work either.

Am I missing something, or should I submit an enhancement request?



import std.traits : hasUDA;

enum test;

struct Foo
{
    int x;

    bool checkUDA()
    {
        static if (hasUDA!(this, test))
        {
                return true;
        }
        else
        {
                return false;
        }
    }
}


void main()
{
    import std.stdio : writeln;

    @test Foo foo = Foo(1);
    static assert(hasUDA!(foo, test));

    writeln(foo.checkUDA()); //prints false, expected true
}

Reply via email to