Implicit type conversion

Michal Minich michal.minich at
Sat Jan 8 13:16:54 PST 2011

Use case:

import std.variant;

void foo (Variant v) {}

void main () {
    Variant v = 3; // ok, this (....) called
    v = 3;         // ok, opAssing  called
    foo (v);       // ok, struct copy, this(this) called
    foo (3);       // error

I'm trying to understand what is needed to make this work from language 
design perspective. Is there already known/proposed solution to make this 
work? What comes to my mind as first - Variant constructor should be 
called on last line, the same way as on the first. But maybe to solve 
this, another operator is needed, opImplicitConvertFrom ...

Second question. Why is needed to have both - strut constructor (this) 
and opAssing. In variant case, constructor just forwards to opAssing. 
>From high level point of view, I don't see any reason both should behave 

More information about the Digitalmars-d-learn mailing list