Reading Atributes (UDA) of overloaded functions

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 17 05:36:41 PDT 2015


On Thursday, 17 September 2015 at 11:47:40 UTC, Ozan wrote:
> Hi!
>
> Is it possible to read all attributes in case of overloading 
> functions? Example:
>
> struct Att { string name; }
> struct Att2 { string name; }
> @Att void testUDA(string x) { writeln("test(string ",x,")"); }
> @Att2 void testUDA(int x) { writeln("test(string ",x,")"); }
>
> void main(string[] args)
> {
> 	testUDA("aaa");
> 	testUDA(100);
>
> 	foreach (attr; __traits(getAttributes, testUDA)) {
> 		if (attr.stringof == "Att") writeln("Found Att");
> 		if (attr.stringof == "Att2") writeln("Found Att2");
> 	}
> }
>
> results in one (!) "Found Att".
> Seems like "First comes, first wins".
>
> Regards, Ozan

use __traits(getAttributes, /*...*/) on each of the members of 
the result of __traits(getOverloads, /*...*/)


More information about the Digitalmars-d-learn mailing list