const/immutable violation?

2011-04-30 Thread Ashish Myles
I saw examples in the D Programming Language book (Page 256) where opAssign() took a ref argument instead of a const ref. So I figured I would test it out and see if the compiler complains if I try to assign a const or immutable struct to another one. import std.stdio; struct Foo { auto r

Bug or feature? std.c.stdlib.exit() breaks RAII

2011-12-29 Thread Ashish Myles
std.c.stdlib.exit() seems to break RAII. The code below tests this both using a struct destructor and an explicit scope(exit) {}. Is this an intentional feature or a bug? import std.stdio; import std.c.stdlib; void main() { struct SafeExit { ~this() { writeln("Safely exit

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2011-12-29 Thread Ashish Myles
On Thu, Dec 29, 2011 at 12:22 PM, Jakob Ovrum wrote: > On Thursday, 29 December 2011 at 16:27:33 UTC, Ashish Myles wrote: >> >> std.c.stdlib.exit() seems to break RAII. The code below tests this >> both using a struct destructor and an explicit scope(exit) {}.  Is >>

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2011-12-29 Thread Ashish Myles
On Thu, Dec 29, 2011 at 1:26 PM, Andrej Mitrovic wrote: > Probably the easiest thing to do is to throw a custom exception and > catch it somewhere in main() to return your status code. Unlike > exit(), throwing will take care of RAII stuff. Thanks, Andrej. That option had occurred to me, but I fi

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2011-12-29 Thread Ashish Myles
On Thu, Dec 29, 2011 at 7:16 PM, Jonathan M Davis wrote: > > A D exit function would have to do essentially the same thing as throw an > exception and catch it in main anyway. The only way that the stack is going to > be unwound properly is if you actually unwind it. The only way in the language >

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2011-12-30 Thread Ashish Myles
On Fri, Dec 30, 2011 at 5:43 AM, Jonathan M Davis wrote: > On Thursday, December 29, 2011 23:03:23 Ashish Myles wrote: >> Since D >> could conceivably implement a very safe exit() without an explicit use >> of Exceptions to get around the "catch Exception() {}"

Re: Bug or feature? std.c.stdlib.exit() breaks RAII

2011-12-30 Thread Ashish Myles
Thanks, Jonathan, for your detailed answer. Ashish On Fri, Dec 30, 2011 at 1:41 PM, Jonathan M Davis wrote: > On Friday, December 30, 2011 10:45:43 Ashish Myles wrote: >> Ok, now there are two issues here: >> IMPLEMENTATION: Implementation of a safe_exit() without an explic

Supporting and signature-checking all foreach variations

2012-02-25 Thread Ashish Myles
I want to define a general-purpose centroid computer for point containers and ran into a couple of challenges. Firstly, here is the basic code Point3 computeCentroid(PointContainer)(const ref PointContainer C) if (...)// want a signature constraint for usability of foreach {

Re: Supporting and signature-checking all foreach variations

2012-02-25 Thread Ashish Myles
On Sat, Feb 25, 2012 at 11:37 AM, Alex Rønne Petersen wrote: > On 25-02-2012 17:25, Ashish Myles wrote: >> >> 1. Since support for foreach can be added in many ways (with >>   ref/non-ref/const variants), I wanted to check if there was any >>   signature constra

Re: Supporting and signature-checking all foreach variations

2012-02-26 Thread Ashish Myles
On Sun, Feb 26, 2012 at 5:25 AM, Ali Çehreli wrote: > On 02/25/2012 08:25 AM, Ashish Myles wrote: >>    However the code above doesn't seem to work and requires me to >>    explicitly invoke the slice operator myself like >>      foreach(p; C[]) { ... } >>  

Re: D 50% slower than C++. What I'm doing wrong?

2012-04-15 Thread Ashish Myles
On Sun, Apr 15, 2012 at 5:16 PM, Somedude wrote: > Le 15/04/2012 09:23, ReneSac a écrit : >> On Sunday, 15 April 2012 at 02:56:21 UTC, Joseph Rushton Wakeling wrote: On Saturday, 14 April 2012 at 19:51:21 UTC, Joseph Rushton Wakeling wrote: > GDC has all the regular gcc optimization