Blogpost about the T.init problem

Timothee Cour thelastmammoth at gmail.com
Thu Jul 12 20:21:56 UTC 2018


the following seems like a easy enough workaround:
just add

` if(this is typeof(this).init) return;` at 1st line of your invariant:

```d
import std.typecons;
import std.range;

struct MyDomainData {
     string username;

     this(string username) @safe
     in(!username.empty)
     do { this.username = username; }

     invariant {
      if(this is typeof(this).init) return;
      assert(!username.empty);
    }

     string toString() { return null; }

     ~this() @safe { }
}

void main(){
  Nullable!MyDomainData b;
}
```
On Thu, Jul 12, 2018 at 9:00 AM Luís Marques via
Digitalmars-d-announce <digitalmars-d-announce at puremagic.com> wrote:
>
> On Wednesday, 11 July 2018 at 03:00:48 UTC, Ali wrote:
> > Somehow, this is the type of problem, i thought point 1 in the
> > vision document is aimed to solve
> > https://wiki.dlang.org/Vision/2018H1
> >
> > "1. Lock down the language definition: D is a powerful language
> > but its definition is not precise enough. A number of
> > subtleties can only be assessed only by running the compiler,
> > not by perusing the specification. This semester we are pushing
> > for a better, more precise, and more complete specification of
> > the D language."
> >
> > ensuring that the language features are coherent together
>
> I think that point isn't supposed to be so ambitious. I think it
> only refers to the fact that the documentation isn't particularly
> formal/precise/complete regarding some language details. Making
> the language features more coherent and compatible among
> themselves is a whole other goal, independent of that one, IMO.



More information about the Digitalmars-d-announce mailing list