Default struct constructors with pure

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 7 16:45:08 PDT 2010


On Thursday, October 07, 2010 16:42:47 Denis Koroskin wrote:
> On Fri, 08 Oct 2010 03:31:54 +0400, Jonathan M Davis <jmdavisProg at gmx.com>
> 
> wrote:
> > Isn't the main
> > problem with having default constructors for structs that the default
> > constructor must result in the same value every time so that the
> > compiler can
> > set init appropriately?
> 
> Problem is that requirement is too restrictive. If ctor is pure, doesn't
> access globals and results in perfectly same objects, then why can't you
> do the initialization at compile-time? You usually can, that's not the
> issue.
> The issue is that sometimes you need to call external functionals that are
> not pure in general (e.g. allocate some resources, initialize fields with
> unique values, register itself somewhere etc).

With the relaxed purity rules (which should be in the next release of dmd), that 
problem should be somewhat mitigated. But you still won't be able to call 
globals.

- Jonathan M Davis


More information about the Digitalmars-d mailing list