Re: T.init, struct destructors and invariants - should they be called?

2018-07-10 Thread FeepingCreature via Digitalmars-d
On Tuesday, 10 July 2018 at 00:01:28 UTC, Steven Schveighoffer wrote: On 7/7/18 11:06 PM, FeepingCreature wrote: On Friday, 6 July 2018 at 23:37:30 UTC, Simen Kjærås wrote: As for alignment, GC, and possibly other things, the code was not intended as a complete implementation of Nullable, only

Re: T.init, struct destructors and invariants - should they be called?

2018-07-09 Thread Steven Schveighoffer via Digitalmars-d
On 7/7/18 11:06 PM, FeepingCreature wrote: On Friday, 6 July 2018 at 23:37:30 UTC, Simen Kjærås wrote: As for alignment, GC, and possibly other things, the code was not intended as a complete implementation of Nullable, only to show that an actual member of type T is not necessary. These

Re: T.init, struct destructors and invariants - should they be called?

2018-07-07 Thread FeepingCreature via Digitalmars-d
On Friday, 6 July 2018 at 23:37:30 UTC, Simen Kjærås wrote: As for alignment, GC, and possibly other things, the code was not intended as a complete implementation of Nullable, only to show that an actual member of type T is not necessary. These issues are fixable, if perhaps nontrivial in

Re: T.init, struct destructors and invariants - should they be called?

2018-07-06 Thread Simen Kjærås via Digitalmars-d
On Friday, 6 July 2018 at 12:31:50 UTC, FeepingCreature wrote: On Friday, 6 July 2018 at 12:10:58 UTC, Simen Kjærås wrote: The rest looks sensible to me, but I have to say this is bollocks. This Nullable never has to construct an S.init: struct Nullable(T) { ubyte[T.sizeof] _payload;

Re: T.init, struct destructors and invariants - should they be called?

2018-07-06 Thread FeepingCreature via Digitalmars-d
On Friday, 6 July 2018 at 12:10:58 UTC, Simen Kjærås wrote: The rest looks sensible to me, but I have to say this is bollocks. This Nullable never has to construct an S.init: struct Nullable(T) { ubyte[T.sizeof] _payload; bool _hasValue; Come on, at least make it a union with a

Re: T.init, struct destructors and invariants - should they be called?

2018-07-06 Thread Simen Kjærås via Digitalmars-d
On Friday, 6 July 2018 at 10:44:09 UTC, FeepingCreature wrote: Why is this a problem? ("Just don't use S.init!") Well, for one it makes Nullable!S impossible. Nullable, if it is to be @nogc, *necessarily* has to construct an S.init struct member. The rest looks sensible to me, but I have to

Re: T.init, struct destructors and invariants - should they be called?

2018-07-06 Thread FeepingCreature via Digitalmars-d
On Friday, 6 July 2018 at 10:44:09 UTC, FeepingCreature wrote: Consider the humble struct S { Object obj; invariant { assert(this.obj !is null); } @disable this(); this(Object obj) in(obj !is null) { this.obj = obj; } } Oops - there should of

T.init, struct destructors and invariants - should they be called?

2018-07-06 Thread FeepingCreature via Digitalmars-d
I believe there's a good case that struct invariants should not be called on struct destruction. Significantly, I believe that Phobos, in particular `moveEmplace`, is already written as if this is the case, even though it is not specified anywhere. It is very common for structs' .init to