Attributes on Enum Members: Call for use cases.

John j at t.com
Wed Nov 29 22:42:26 UTC 2017


On Wednesday, 29 November 2017 at 21:46:51 UTC, Timon Gehr wrote:
> On 29.11.2017 20:49, Steven Schveighoffer wrote:
>> On 11/29/17 2:01 PM, Timon Gehr wrote:
>> 
>> OK, now I get what you are saying. In the same vein, I tested 
>> applying attributes to functions themselves:
>> 
>> @("a") int fun() { return 0; }
>> pragma(msg, typeof(&fun)); // int function()
>> 
>> @("b") int gun() { return 1; }
>> pragma(msg, typeof(&gun)); // int function()
>> 
>> void main()
>> {
>>    auto f = &fun;
>>    f = &gun; // works
>> }
>> 
>> Given that, it seems attributes play no part in the type 
>> itself, they are just metadata in the compiler.
>
> Well, I think the case of UDAs on parameters is closer to:
>
> struct S{
>     @("a") int x1;
>     @("b") int x2;
> }
>
> The attributes on x1 and x2 are indeed part of the type S, even 
> if the attributes on S itself are not.
>
> If we go with "UDAs on parameters are not part of the function 
> type", how to you get the UDAs of the parameters of some 
> function?

The function would have to be passed directly to __traits() to 
get the UDA. If passed to a function, it would have to be via 
alias:

void func(@attr int param) { }

void test(alias f)()
{
     writeln(getParameterAttr!(f, 0)); // or however to implement 
getting the attribute
}

test!func(); // prints @attr


More information about the Digitalmars-d mailing list