Forwarding constructor arguments to super

2010-06-12 Thread pillsy
Is there a good way to forward constructor arguments to a superclass 
constructor? I.e., if I have
something like this

class Foo {
  int _x;

  this (int x) { _x = x; }
}

class Bar : Foo {}

I'd like to able to have this just work:

auto bar = new Bar(3);

However, doing this means that DMD complains that Bar.this isn't callable with 
an int argument. The
next thing I tried was

class Bar : Foo
{
  this (Args) (Args... args) { super(args): }
}

at which point DMD complains that constructor Bar.this conflicts with template 
Bar.__ctor(Args...). I'm
using DMD 2.046, if it matters.

Thank you,
Pillsy


Re: Finding and invoking struct destructors in D2

2010-05-27 Thread Pillsy
== Quote from div0 (d...@users.sourceforge.net)'s article:
[...]
> Most important is this one, which scuppers any change of doing
> a shared ptr like struct:

> http://d.puremagic.com/issues/show_bug.cgi?id=3516

Yeah, that basically kills the idea until the bug is fixed. :(

Once it is, I think a hasDestructor template would be a good thing
to have in the standard library.

Cheers,
Pillsy


Finding and invoking struct destructors in D2

2010-05-27 Thread Pillsy
Hi, all,

I was wondering if there's any way to determine at compile time
whether a struct has a (non-trivial) destructor associated with it,
and whether there's any way to call that destructor without using
the delete operator. It seems like being able to do these two
things would allow you to make a container that plays well with
structs that are designed to do (say) reference counting, but I
don't see anything in the spec on the website that shows how this
might be accomplished.

Thanks!
Pillsy


Confusing behavior involving array operations.

2010-05-14 Thread Pillsy
I have the following program on Mac OS X 10.6.3 running dmd version 2.043:

$ cat if.d
import std.stdio;

void main (string [] args)
{
  foreach(arg; args)
writeln(arg);

  auto vec = new double[10];

  foreach(i, ref x; vec) { x = cast(double) i; }

  if (args.length > 1 && args[1] == "bar") { vec[] *= 0.5; }
}

This program compiles with no warnings. However, when I run it, I get a bus 
error regardless of the
value of the first command-line argument, or whether it's present at all. I 
also get bus error if I
eliminate the conditional altogether. AFAICT, the array operation I'm doing on 
vec is legitimate
according to

http://www.digitalmars.com/d/2.0/arrays.html

and the fact that the program bombs out regardless of the outcome of the test 
in the conditional is
particularly mystifying.

Any help would be greatly appreciated.

Thanks,
Pillsy