Time to kill T() as (sometimes) working T.init alias ?
Dmitry Olshansky
dmitry.olsh at gmail.com
Thu Nov 29 09:44:56 PST 2012
11/29/2012 9:12 PM, jerro пишет:
>> The original idea is that there should be *no such thing* as default
>> construction of a struct as being anything other than T.init. The
>> default construction of a struct should be a compile time creature,
>> not a runtime one.
>>
>> Any methods or workarounds to try and make T() produce something
>> different from T.init is bad D practice. The compiler tries to
>> statically head them off, but probably should do a better job of that.
>
> The only reason to associate no parameter constructors with default
> values is because of how C++ works. There is no reason why
>
> Foo foo; (1)
>
> should be equivalent to
>
> auto foo = Foo(); (2)
>
> in D. We could allow constructors with no parameters and make (1)
> equivalent to
>
> auto foo = Foo.init; (3)
>
> The current workaround when one wants (2) to construct the object at
> runtime is to define a static opCall, but that's messy and inconsistent.
> It's just one more quirk one needs to learn to effectively use the
> language.
Yup. It looks like a poorly copied syntactic carry-over from C++ that
doesn't quite make sense in the presence of T.init.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list