Template struct literals should infer template parameters

Philippe Sigaud philippe.sigaud at gmail.com
Sun Aug 7 00:59:07 PDT 2011


On Sat, Aug 6, 2011 at 22:19, Sean Eskapp <eatingstaples at gmail.com> wrote:
> If I have something like
>
>    struct S(T)
>    {
>        T data;
>    }
>
>   I can't make a struct literal with
>
>    int mystuff;
>    someFunc(S(mystuff));
>
> I have to use
>
>    int mystuff;
>    someFunc(S!(int)(mystuff));
>
> Why is this?

Yeah, function templates have a way to automatically determine their
template parameters (IFTI : Implicit Function Template
Instantiation?), but that doesn't work with struct and class
constructors. Too bad.

You can use a factory function to do just that, it's a one-liner:

auto s(T)(T t) { return S!(T)(t); }

and then:

someFunc(s(mystuff));


More information about the Digitalmars-d mailing list