cast(function qualifier)
Atila Neves
atila.neves at gmail.com
Mon Feb 3 18:38:51 UTC 2025
https://forum.dlang.org/post/v0urjh$58i$1@digitalmars.com
On Thursday, 2 May 2024 at 01:51:45 UTC, Timon Gehr wrote:
> 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.
This looks nice.
More information about the dip.ideas
mailing list