[Issue 9114] Can't call varadic template function with partly specified template parameters
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jun 1 09:51:11 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=9114
--- Comment #2 from Andrej Mitrovic <andrej.mitrovich at gmail.com> ---
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]);
}
-----
--
More information about the Digitalmars-d-bugs
mailing list