On Saturday, 30 March 2024 at 22:37:53 UTC, Carl Sturtivant wrote:
> I'm inclined to a view that keeps more "it just works" options open. Regard the parameter names as a part of the type (which I am very grateful for them being currently) and just regard part of the definition of "type equality" as being to ignore parameter names when comparing types.
With this viewpoint, ParameterIdentifierTuple should be repaired to work with function types just as it works with functions, and the current behavior is a bug.
Maybe, but one of its unittests specifically tests that a function pointer has no parameter identifiers:
// might be changed in the future?
void function(int num, string name) fp;
static assert([ParameterIdentifierTuple!fp] == ["", ""]);
And changing in the future got quite a bit of push back in that PR link.
This is because fp
is declared using a function pointer type, and the author of the test did not think function pointer types should include identifiers. So it seems logical that ParameterIdentifierTuple should not give identifiers for a function type either.
If a function type does include identifiers, then would two function types with the same argument types but different identifiers compare equal using is
?
> Incidentally, I tried
extern typeof(foo) func;
to say that func was an actual function (extern
so defined elsewhere) whose type was the type of the function int foo(int num, string name, int);
so I can then use ParameterIdentifierTuple
on a function, not a type,
Nice try!
> but the compiler said bug1.d(5): Error: variable ``bug1.func`` cannot be declared to be a function
. Seems unreasonable given the implied semantics.
Yes, it's not possible to instantiate a function type.