D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9114 - Can't call varadic template function with partly specified template parameters
Summary: Can't call varadic template function with partly specified template parameters
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86_64 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-05 10:46 UTC by Mathias Baumann
Modified: 2023-02-11 04:06 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias Baumann 2012-12-05 10:46:41 UTC
The test case:

module main;

void test ( int a, Args...) ( Args args ){}

void main ( char[][] arg)
{
    test!(5)(3);
}

The error:

main.d(7): Error: function main.test!(5).test (() args) does not match parameter types (int)
main.d(7): Error: expected 0 arguments, not 1 for non-variadic function type void(() args)


In D2 this compiles without problem.
Comment 1 Andrej Mitrovic 2016-06-01 16:30:06 UTC
Workaround:

template test (int a)
{
    void test ( Args...) ( Args args ){}
}

void main ( char[][] arg)
{
    test!(5)(3);
}
Comment 2 Andrej Mitrovic 2016-06-01 16:51:11 UTC
Here's another workaround, where you can simply declare an alias in your code via `alias FixedForward!(target_func) fixed_func` and use it regularly.

-----
import tango.core.Traits;

// the magic
template FixedForward ( alias func )
{
    struct FixedForward ( T )
    {
        static ReturnTypeOf!(func!(T)) opCall ( X ... ) ( X x )
        {
            return func!(T, X)(x);
        }
    }
}

// the target function you want to fix
T[] test ( T, Args...) ( Args args ) { return cast(T[])[args]; }

// just declare an alias of it
alias FixedForward!(test) FixedTest;

// works at ctfe
const static_result = FixedTest!(short)(1, 2, 3);

alias short[] ShortArray;

static assert(is(typeof(static_result == ShortArray)));
static assert(static_result == cast(short[])[1, 2, 3]);

void main ( char[][] arg)
{
    // works at rtfe
    auto result = FixedTest!(short)(1, 2, 3);

    static assert(is(typeof(result == ShortArray)));

    assert(result == cast(short[])[1, 2, 3]);
}
-----