eating inout dogfood
Michel Fortin
michel.fortin at michelf.com
Mon Oct 17 06:12:43 PDT 2011
On 2011-10-17 12:26:17 +0000, "Steven Schveighoffer"
<schveiguy at yahoo.com> said:
> On Fri, 14 Oct 2011 20:21:59 -0400, Michel Fortin
> <michel.fortin at michelf.com> wrote:
>
>> 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?
For some reason I couldn't make it work with the constraint, but this
works fine with the current compiler:
struct S(T)
{
this(U)(in S!U other)
{
this.x = other.x;
}
T * x;
}
void main()
{
S!(int) ptr;
S!(const(int)) cptr = ptr;
}
Whether it's intended or not I don't know. Ask Walter.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list