Trying to use Mir ion, its a perfect example of the failure of D's attribute system

H. S. Teoh hsteoh at qfbox.info
Fri Jan 20 17:13:15 UTC 2023


On Fri, Jan 20, 2023 at 11:49:42AM +0000, Quirin Schroll via Digitalmars-d wrote:
[...]
> The correct version is this:
> ```D
> void process(DG : void delegate())(DG callback) { callback(); }
> ```
> 
> This has two drawbacks:
> 1. `process` cannot be virtual.
> 2. the argument bound to `callback` cannot have its parameter types
> inferred.

And 3.: it causes the body of `process` to be duplicated across multiple
instantiations, even if the only difference in DG is in attributes,
i.e., the generated code is 100% identical.  This leads to template
bloat.


[...]
> The drawbacks are lots of template instantiations and that it always
> generates 16 overloads.

Exactly. The language needs to support this natively, not leave it up to
workarounds that bring in lots of template bloat.


T

-- 
Famous last words: I *think* this will work...


More information about the Digitalmars-d mailing list