Challenge
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 3 07:06:57 PDT 2016
On Monday, 3 October 2016 at 13:41:13 UTC, Manu wrote:
> I'm finding this rather annoying:
>
> struct S
> {
> static @property int p() { return 10; }
> }
>
> pragma(msg, typeof(&S.p)); // prints: int function() @property
> pragma(msg, is(typeof(&S.p) == function)); // prints: false
>
> It looks like a function... but I can't identify it as a
> function!
It works if both:
a) you remove @property
b) you don't convert it to function pointer
struct S
{
static int p() { return 10; }
}
pragma(msg, is(typeof(S.p) == function); // true
Sadly `is(X == function)` is very obscure and confusing because
it doesn't do what one may expect it to do. In current form it
can only be used if something is a function declaration,
everything else is `false`. It is not even possible to manually
express a type which will pass `is(T == function)`, you can only
get `true` by applying `typeof` to existing function declaration.
And @property screws it because the only current effect of
property is exactly changing result of `typeof(propertyFoo)` from
function type to result type.
More information about the Digitalmars-d
mailing list