https://issues.dlang.org/show_bug.cgi?id=21065
Mathias LANG <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #1 from Mathias LANG <[email protected]> --- Regarding your proposed implementation: > T __makeClassObject(T, A...)(auto ref A); This would have the effect of producing a potentially large amount of template instances, as the `auto ref` variadic will match the parameters *exactly* - something we don't really want, e.g. when instantiating `class Foo { this (int) {} }` and passing `short`. Additionally, with this change the implicit conversions don't work anymore (e.g. passing `ulong.init` will give it a `ulong` which will error when attempting to implicitly convert it to `int`). What I found to be working very well when doing this kind of forwarding was to instead *generate* an overload set and let the compiler do the heavy lifting for me. In this case, the definition would become: > template __makeClassObject (T) And have multiple `__makeClassObject (args)` functions defined in it, each one accepting exactly the parameter of one constructor definition. Alternatively, just leave the initialization where it currently is (the compiler) and just templatize `newclass` to sidestep this issue. --
