Default struct constructors with pure

Denis Koroskin 2korden at gmail.com
Thu Oct 7 16:42:47 PDT 2010


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).


More information about the Digitalmars-d mailing list