On Fri, 14 Oct 2011 20:21:59 -0400, Michel Fortin <[email protected]> wrote:

On 2011-10-14 20:05:09 +0000, "Steven Schveighoffer" <[email protected]> said:

I don't think the compiler will auto-convert someTemplate!(inout(V)) to e.g. someTemplate!(const(V)). Does that work? I know that for instance, I can't do this:
 struct S(T)
{
    T * x;
}
 S!(int) ptr;
S!(const(int)) cptr = ptr;
 So I wouldn't expect the compiler to do the above translation either...

Perhaps you can add this to the struct:

        void this(U)(in S!U other) if (__traits(compiles, this.x = other.x))
        {
                this.x = other.x;
        }

If that works, maybe a similar approach could be used to solve the problem with inout: if you can construct the requested type from the provided one it get converted automatically at the call site.


This looks promising. However, I seem to recall D specifically disallowing implicit conversion using a constructor...

Is this going to fly with Walter?

-Steve

Reply via email to