November 02, 2018 Re: Dealing with raw types as attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Neia Neutuladh | On Friday, 2 November 2018 at 04:18:47 UTC, Neia Neutuladh wrote:
> On Fri, 02 Nov 2018 04:01:00 +0000, Nicholas Wilson wrote:
>> By noting that all (interesting for the purpose of UDA's i.e. not void)
>> types have a .init
>>
>> or you could do
>>
>> static if (is(typeof(uda) == Foo) || is(uda == Foo))
>
> Which, again, only tests for presence, when I want to check for presence *and* get the value, which should be Foo.init if the person supplied the raw type.
template GetMeTheValue(value...) if(value.length == 1)
{
static if (is(typeof(value[0].init == value[0]) // A type
enum GetMeTheValue = value[0].init;
else
enum GetMeTheValue = value[0];
}
...
static if (is(typeof(GetMeTheValue!uda) == Foo)
|
November 02, 2018 Re: Dealing with raw types as attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Neia Neutuladh | On Thursday, 1 November 2018 at 16:14:45 UTC, Neia Neutuladh wrote:
> The spec says that a user-defined attribute must be an expression, but DMD accepts a wide range of things as UDAs:
>
> struct Foo { string name = "unknown"; }
> @Foo int bar;
IIRC symbol reference is a primary expression.
|
Copyright © 1999-2021 by the D Language Foundation