Thread overview |
---|
July 29, 2016 FunctionTypeOf behaves unexpectedly for function pointers? | ||||
---|---|---|---|---|
| ||||
This failure seems curious and I haven't been able to understand why it occurs, or whether it might be intentional. For all other callable types, including functions and delegates and types implementing opCall, the assertion passes. import std.traits : FunctionTypeOf; void function() func; // Error: static assert (is(void() == void function())) is false static assert(is(FunctionTypeOf!func == typeof(func))); |
July 30, 2016 Re: FunctionTypeOf behaves unexpectedly for function pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | On Friday, 29 July 2016 at 13:54:13 UTC, pineapple wrote:
> This failure seems curious and I haven't been able to understand why it occurs, or whether it might be intentional. For all other callable types, including functions and delegates and types implementing opCall, the assertion passes.
>
> import std.traits : FunctionTypeOf;
> void function() func;
> // Error: static assert (is(void() == void function())) is false
> static assert(is(FunctionTypeOf!func == typeof(func)));
func is a pointer to a function but FunctionTypeOf extracts the target type.
So the correct assertion is
static assert(is(FunctionTypeOf!func* == typeof(func)));
I can't believe that it worked for delegates because the same happens. It extracts the target type, i.e it discards the information saying that it's a member function:
import std.traits;
void function() fun;
void delegate() dlg;
static assert(is(FunctionTypeOf!fun* == typeof(fun)));
static assert(is(FunctionTypeOf!dlg* == typeof(fun)));
|
August 01, 2016 Re: FunctionTypeOf behaves unexpectedly for function pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Saturday, 30 July 2016 at 12:54:32 UTC, Basile B. wrote:
> func is a pointer to a function but FunctionTypeOf extracts the target type.
> So the correct assertion is
>
> static assert(is(FunctionTypeOf!func* == typeof(func)));
>
> I can't believe that it worked for delegates because the same happens. It extracts the target type, i.e it discards the information saying that it's a member function:
>
> import std.traits;
> void function() fun;
> void delegate() dlg;
> static assert(is(FunctionTypeOf!fun* == typeof(fun)));
> static assert(is(FunctionTypeOf!dlg* == typeof(fun)));
Ah, that makes sense. Thank you!
|
Copyright © 1999-2021 by the D Language Foundation