Get UDAs of self's declaration as a member?
    Ali Çehreli 
    acehreli at yahoo.com
       
    Tue Apr 26 01:13:29 UTC 2022
    
    
  
On 4/25/22 14:32, cc wrote:
 > Hard to word this question right, but is it possible to get the UDAs
 > assigned to a class/structure's member variable declaration, within that
 > variable's definition?  e.g.
That sounds backwards to me too. :) Policy-based design can work here:
import std.stdio;
import std.traits;
enum SPECIAL { no, yes }
struct Foo(SPECIAL special = SPECIAL.no)  {
     void foo() {
       static if (special == SPECIAL.yes)
         writeln("special");
       else
         writeln("not special");
     }
}
struct Bar {
   Foo!(SPECIAL.yes) foo;
}
alias FooSpecial = Foo!(SPECIAL.yes);
alias FooRegular = Foo!(SPECIAL.no);
void main() {
   Foo!() foo;        // <-- Without the aliases
   FooSpecial foo_;   // <-- Better syntax with aliases
   foo.foo;
   Bar bar;
   bar.foo.foo;
}
Ali
    
    
More information about the Digitalmars-d-learn
mailing list