dmd 1.070 and 2.055 release

Ali Çehreli acehreli at yahoo.com
Sun Sep 11 21:11:42 PDT 2011


On Sun, 11 Sep 2011 18:07:41 -0700, Walter Bright wrote:

> On 9/11/2011 4:53 PM, Ali Çehreli wrote:
>> The problem is, the disabled default constructor of a *member* is
>> making a wrapper class's constructor to be disabled as well:
> 
> Right. It's infectious. This is deliberate.
> 
>  > I think this is at least limiting and very
> likely a bug.
> 
> It's deliberate. It's likely that we can find ways to loosen things up
> in the future, but the idea is to screw it down tight, first, instead of
> allowing big holes.

It is common that types insist on some data when being constructed. Many 
of my C++ types cannot be default-constructed. I love the idea.

So S insists that an int must be provided during its construction. That 
is great.

But although one of the major tasks of C's constructor is to initialize 
its members, it cannot initialize an S member no matter how it tries.

I can see two workarounds, none of which I believe are undesirable:

1) Insist that C defines a non-default constructor but ignores the 
argument with an arbitrary type:

struct S
{
    @disable this();
    this(int x)
    {}
}

class C
{
    S s;

    this(int)
    {
        this.s = S(42); // Always 42; ignores the arg
    }
}

void main()
{
    auto c = new C(0); // Unused 0
}

2) Use a pointer:

class C
{
    S * s;    // Expensive in space

    this()
    {
        this.s = new S(42);  // Expensive in time
    }
}

void main()
{
    auto c = new C;
}

Ali


More information about the Digitalmars-d-announce mailing list