On Saturday, 22 June 2013 at 16:31:16 UTC, Namespace wrote:
On Saturday, 22 June 2013 at 16:08:01 UTC, Andrej Mitrovic wrote:
On 6/22/13, monarch_dodra <monarchdo...@gmail.com> wrote:
I think you can work around the problem using "appender":
auto buffer = appender!(int[])();

Yes, because it has a default argument which it passes to the Appender constructor. If only we had default constructors for structs in D.. or a general solution to this issue. I remember maybe a year ago or so I've ran into the same issue with hashes, and now it almost bit me
hard again (luckily this was caught immediately in a failing
unittest).

What was the main reason for Walter to disable default CTors for structs?

So that *default* construction can be evaluated statically, which then means .init can exist, which allows all of D's postblit mechanics, as well as move semantics.

It also means that declaring statics in a function is possible and doesn't require any special run-time code for first initialization.

I think the problem is that since in C++ "no-arg => default", they removed constructors that took no arguments, so as to avoid any confusion, or maybe they just didn't realize that someone might want to runtime construct something, but have no arguments to pass to the constructor.

IMO, there was a *little* bit of lack of hindsight on that one, but the choice was clearly superior to C++'s CC scheme on return by value...

Reply via email to