Struct no-arg constructor?
monarch_dodra
monarchdodra at gmail.com
Wed Jul 25 03:45:48 PDT 2012
On Wednesday, 25 July 2012 at 10:40:22 UTC, deadalnix wrote:
> Static opCall isn't a solution. You can't new on it. And it
> seems weird that you can disable something that don't possibly
> exists in the first place.
>
> This topic comes back again and again on the NG, it have to be
> considered.
>
> If I get a concrete example, let say RefCounted, I can see in
> the source code that many checks are performed to handle the
> case where the struct is .init . It have a runtime cost and
> make the code more complex.
>
> It is more error prone because specific cases must be handled
> all over the place. Having .init is certainly an interesting
> capability of D, but in this specific case, it isn't sure it
> worth it.
I think a good solution would be to simply allow structs to have
a "no-argument constructor".
However, we'd have to hammer in the fact that this "no-argument
constructor" is NOT a "default constructor" that always gets
called. It is an explicit constructor, just like any other, but
doesn't take any arguments.
It seems straight forward, simple and intuitive to me actually.
More information about the Digitalmars-d
mailing list