[Issue 13196] Infer struct/class template args from constructor args
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Jul 24 09:22:30 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13196
Steven Schveighoffer <schveiguy at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy at yahoo.com
--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.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?
I'll respond here since the question is here.
Answer: you don't. Just like you can't do IFTI on this:
template foo(T)
{
static if(is(T == bool))
void foo(T t) {}
else
void foo(int t) {}
}
--
More information about the Digitalmars-d-bugs
mailing list