Possible bug

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 25 12:35:46 PDT 2013


On Mon, 25 Mar 2013 11:11:40 -0400, Sergei Nosov <sergei.nosov at gmail.com>
wrote:

> On Monday, 25 March 2013 at 14:12:17 UTC, bearophile wrote:
>> Sergei Nosov:
>>
>>> Everything's fine if I specify parameters explicitly:
>>> <pre>
>>> test!int hello = test!int(cptr);
>>> </pre>
>>
>> Some persons have proposed alternative designs, but D is working as  
>> currently designed here... Unlike template functions, templated structs  
>> don't infer the type.
>>
>> Bye,
>> bearophile
>
> Thx, is there any good rationale?

There really isn't.  I have created an enhancement request that you might
be interested in voting for.

http://d.puremagic.com/issues/show_bug.cgi?id=6082

Note that auto is your friend here to avoid the dual-specification of the  
template:

auto hello = test!int(cptr);

And you can always create a wrapper function:

test!T mktest(T)(T *ptr) { return test!T(ptr);}

...

auto hello = mktest(cptr); // no explicit instantiation required

-Steve


More information about the Digitalmars-d-learn mailing list