[Issue 13196] Infer struct/class template args from constructor args

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 23 23:22:38 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13196

--- Comment #2 from Manu <turkeyman at gmail.com> ---
(In reply to Jakob Ovrum from comment #1)
> This has been discussed before, and there is even a DIP for it. See #6082.
> 
> It's not so easy to do in the general case:
> 
> ---
> struct S(T)
> {
>     static if(is(T == bool))
>     {
>         this(T[] t) {}
>     }
>     else
>     {
>         this(int i) {}
>     }
> }
> 
> auto s = S([true, false]);
> auto s2 = S(2);
> ---
> 
> How do you propose we deduce T for the above two?
> 
> *** This issue has been marked as a duplicate of issue 6082 ***

I don't think your example represents the 'general case'.
In this example I expect there must be a compile error; the static if can't be
resolved without T specified explicitly, so no constructor can be known to
exist, so it can't possibly even attempt to be inferred.

--


More information about the Digitalmars-d-bugs mailing list