Implicit Constructors

Steven Schveighoffer schveiguy at yahoo.com
Fri Oct 13 14:37:25 UTC 2017


On 10/13/17 10:28 AM, Adam D. Ruppe wrote:
> On Friday, 13 October 2017 at 14:22:05 UTC, Meta wrote:
>> It'd be nice if it did, because I believe it would enable the following:
> 
> I don't think so, since the implicit construction would only work one 
> level deep. So you can implicit construct the array, but not the 
> individual variants in the array.

I concur, it's easily testable:

class C
{
    this(int x) {}
}
void foo(C a ...)
{
}

void bar(C[] a ...)
{
}

void main()
{
    foo(0); // works
    bar(0); // does not work.
}

However, this could be useful:

foo(Variant v ...)
{
}

foo(0);
foo("hello");
...

-Steve


More information about the Digitalmars-d mailing list