Would love to override default ctor of struct
Alex
sascha.orlov at gmail.com
Mon Jan 21 19:08:49 UTC 2019
On Monday, 21 January 2019 at 17:06:55 UTC, Nick Treleaven wrote:
> On Saturday, 19 January 2019 at 11:01:14 UTC, Alex wrote:
>>> 2. not everything can be set using member initializer because
>>> of CTFE limitations.
>>
>> Hm... ok. But even then, if something does not work in the way
>> it should because of limitations: What prevents of setting the
>> parameter inside a function after or on creation?
>
> Performance for repeated function calls after construction, we
> don't want an extra branch test on each function call and an
> extra bool bloating/tainting fields in the struct.
>
> A pseudo constructor function is a workaround, but is a bit
> ugly, adding a separate symbol you have to check for when
> learning a new library struct, and the function has more
> unnecessary boilerplate vs a constructor.
>
>> Or, using a non-default constructor exactly for these params?
>
> You can't have a zero argument non-default struct constructor.
> I've never been told why:
> https://wiki.dlang.org/Language_issues#Explicit_syntax_and_.40disable_this
>
> Only the default constructor is constrained by .init, explicit
> zero argument construction is unconstrained. It could be
> allowed.
Could you give an example, where a zero argument construction has
to be done, which cannot be accomplished by setting the
appropriate field with a default value?
More information about the Digitalmars-d
mailing list