Would love to override default ctor of struct

Nick Treleaven nick at geany.org
Mon Jan 21 17:06:55 UTC 2019


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.


More information about the Digitalmars-d mailing list