static opCall 'hidden' by incompatible constructors
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 17 10:56:53 PDT 2014
On Thursday, 17 July 2014 at 17:11:29 UTC, Nick Treleaven wrote:
> I want to add a static opCall with no arguments to simulate a
> nullary-argument constructor.
Please don't do it unless you have a _very_ compelling use case.
> As nullary static opCall doesn't conflict with a nullary
> constructor (as the latter can't exist), it would be useful to
> allow it. Otherwise, how can we wrap the construction of a
> class with a nullary constructor?
It has never worked properly (opCall never got called) and being
a bad style going against language design rationale it was
completely banned. More info:
https://issues.dlang.org/show_bug.cgi?id=12124
I believe CTFE-only default struct constructors should be allowed
instead but until this becomes an option, having factory
functions is the way to go ("auto var = unique(new T)" vs
"Unique!T var = new T")
I am pretty sure many D users will disagree though :)
More information about the Digitalmars-d
mailing list