Explicit cast to @system?
Anonymouse
zorael at gmail.com
Sun Oct 9 19:37:15 UTC 2022
On Sunday, 9 October 2022 at 16:25:22 UTC, tsbockman wrote:
> You might be templating more information than necessary. In
> your example `foo` doesn't need to be a template at all:
> ```D
> void foo(void function() @system fun) {
> pragma(msg, typeof(fun).stringof);
> }
> ```
Yes, it was a toy example. It's complicated and I need crayons to
explain it well, but the real code is a nested function in a main
function in a template mixin, mixed into a class in a module
dedicated to it. When invoked the main function introspects
module-level functions annotated with particular UDAs and calls
them -- or doesn't, depending on other factors. Several modules
(grep says 23) then each have their own class types that mix in
this mixin, and each module's module-level functions take that
module's class as parameter. Like the hello world example does
[here](https://github.com/zorael/kameloso/blob/a471a33/source/kameloso/plugins/hello.d#L17-L25).
So the `__FUNCTION__` string of one instance of the nested
function could be (and note the `@safe`):
```
kameloso.plugins.notes.NotesPlugin.IRCPluginImpl!(Flag.no,
"kameloso.plugins.notes").onEventImpl.process!(false, false, void
function(NotesPlugin, ref const(IRCEvent)) @safe).process
```
Even if I somehow manage to change the nested `process` to not be
a template I still need to instantiate the housing
`IRCPluginImpl` mixin once per class (and module), so I'm not
sure. I could just annotate everything `@system` too.
More information about the Digitalmars-d-learn
mailing list