hasUDA with this

jmh530 john.michael.hall at gmail.com
Thu Jul 19 19:18:43 UTC 2018


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
}


More information about the Digitalmars-d-learn mailing list