Can someone explain this error?

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Sep 23 17:18:43 PDT 2008


On Tue, Sep 23, 2008 at 7:56 PM, Sean Kelly <sean at invisibleduck.org> wrote:
> == Quote from Jarrett Billingsley (jarrett.billingsley at gmail.com)'s article
>> On Tue, Sep 23, 2008 at 7:26 PM, Sean Kelly <sean at invisibleduck.org> wrote:
>> >    class C
>> >    {
>> >        this() {}
>> >        this( int x, int y ) {}
>> >    }
>> >
>> >    void main()
>> >    {
>> >        auto c = alloc!(C);
>> >        auto d = alloc!(C)( 1, 2 );
>> >    }
>> >
>> >    T alloc(T, Params ...)( Params params )
>> >    {
>> >        return new T( params );
>> >    }
>> >
>> > $ dmd test
>> > test.d(10): Error: expected 0 arguments, not 2
>> >
>> You cannot partially specify a template.  alloc!(C) means that
>> Params... is the empty tuple: hence, 0 arguments expected.
>> template alloc(T)
>> {
>>     T alloc(Params ...)( Params params )
>>     {
>>         return new T( params );
>>     }
>> }
>> does the trick, but requires you to call it with empty parens in the
>> 0-param case (like "alloc!(C)()").
>
> I'm pretty sure it's possible to partially specify a template.  Consider:
>
>    void main()
>    {
>        fn!(int)( 5 );
>    }
>
>    void fn(A, B)( B b ) {}
>
> This works just fine, but if I change the function declaration to:
>
>    void fn(A, B ...)( B b ) {}
>
> it fails.  Are variadic templates a special case?
>
>
> Sean
>

Uh, what compiler are you using?  That fails for me (1.034).


More information about the Digitalmars-d-learn mailing list