On Tuesday, 6 September 2016 at 13:57:27 UTC, Lodovico Giaretta wrote:
On Tuesday, 6 September 2016 at 13:44:37 UTC, Ethan Watson wrote:
[...]
Suggestions?

Of course I don't know which level of usability you want to achieve, but I think that in this case your bind system, when binding a default ctor, could use @disable this() and define a factory method (do static opCall work?) that calls the C++ ctor.

It's not as good-looking as a true default ctor, but it doesn't provide any way to introduce bugs and it's not that bad (just a couple key strokes).

Correcting my answer. The following code compiles fine:

struct S
{
    static S opCall()
    {
        S res = void;
        // call C++ ctor
        return res;
    }
}

void main()
{
    S s = S();
}

But introduces the possibility of using the default ctor inadvertitely.
Sadly, the following does not compile:

struct S
{
    @disable this();
    static S opCall()
    {
        S res = void;
        // call C++ ctor
        return res;
    }
}

Making this compile would solve your issues.

Reply via email to