std.traits.ParameterIdentifierTuple producing empty results.

Nick Treleaven nick at geany.org
Mon Apr 1 18:20:43 UTC 2024


On Monday, 1 April 2024 at 15:57:23 UTC, Carl Sturtivant wrote:
> As a practical matter right now, it would be good if parameter 
> names continue to be stored in the type of a function or 
> function pointer, as this is (so far as I have been able to 
> ascertain) the only way they are accessible in D. Right now I 
> am extracting them using CTFE!
>
> Again, as a practical matter, it would be good if he purist 
> view of function and function pointer types could be put aside 
> and `ParameterIdentifierTuple` be permitted to work on function 
> and function pointer types,

I don't think it's possible to make the `is(__parameters)` check 
work there without changing the language. Parameter names in a 
function type seem to be lost once that type is used to 
instantiate a template:

```d
void f(T)() {
     static if (is(T PT == __parameters))
         pragma(msg, PT);
}
void foo(int i, char c);
void main()
{
     static if (is(typeof(foo) PT == __parameters))
         pragma(msg, PT);

     f!(typeof(foo));
}
```
Output:
```
(int i, char c)
(int, char)
```
And that makes sense because otherwise a function type with 
different parameter names would need to instantiate a separate 
instance of the template in order to preserve the identifiers. So 
if that happened, function types with different identifiers would 
not always compare equal as types.


More information about the Digitalmars-d mailing list