Bug 9114 – Can't call varadic template function with partly specified template parameters

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86_64
OS
Linux
Creation time
2012-12-05T10:46:41Z
Last change time
2023-02-11T04:06:23Z
Assigned to
No Owner
Creator
Mathias Baumann

Comments

Comment #0 by mathias.baumann — 2012-12-05T10:46:41Z
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 by andrej.mitrovich — 2016-06-01T16:30:06Z
Workaround: template test (int a) { void test ( Args...) ( Args args ){} } void main ( char[][] arg) { test!(5)(3); }
Comment #2 by andrej.mitrovich — 2016-06-01T16:51:11Z
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]); } -----