cast(function qualifier)

Timon Gehr timon.gehr at gmx.ch
Thu May 2 01:51:45 UTC 2024


The status quo is that it is annoying to type-pun function pointers to 
stronger function attributes as the entire type has to be specified:

```d
(cast(int function(int)pure)&f)(2);
```

This is also error prone as the return type and/or argument types could 
go out of sync with the actual type of `f`.


`cast` could simply allow a list of function attributes and cast a 
function pointer or delegate to a type that additionally has those 
attributes:

```d
(cast(pure)&f)(2);
```

This simple syntactic sugar would make it a bit easier to work with 
attributes in `@system`/`@trusted` code. Of course, safety checks would 
still be performed, as for the more explicit cast syntax.


More information about the dip.ideas mailing list