[phobos] Proposal of StopWatch module

Jonathan M Davis jmdavisprog at gmail.com
Wed Aug 18 10:38:29 PDT 2010


On Wednesday, August 18, 2010 10:21:56 SHOO wrote:
> > Line 414: no need for @trusted, casting numbers is not unsafe.
> 
> Error: cast from const(long) to real not allowed in safe code

Maybe to!long will work.

> It's my understanding that there are two reasons why a struct doesn't
> have a default constructer toward.
> Primarily, it can define as a variable without minding an initialization
> method in particular generic programming.
> Second, it ensure the initialization that resource assignment does not
> occur.
> See also: http://j.mp/9KGTFd

According to TDPL, it's because you have to know the struct's init value at 
compile time. You can only have one init, and it's quite possible to create 
default constructors which result in different values even though they don't have 
any parameters. Classes avoid the problem because their reference-based and the 
reference itself is what gets the init. But since structs go on the stack, it 
doesn't work to have an arbitrary default constructor. It might work at some 
point to have default constructors with certain restrictions (like maybe 
purity), but for the moment, we don't have a way to make it work.

- Jonathan M Davis


More information about the phobos mailing list