digitalmars.D.learn - Variadic function template with one inferred template argument
- Ben Jones (17/17) Nov 07 2020 I'm trying to write a function template with 1 parameter whose
- starcanopy (12/29) Nov 07 2020 template f(Ts...) {
- Ben Jones (2/6) Nov 07 2020 Ah, I had discovered a different error when I tried that. Thanks!
I'm trying to write a function template with 1 parameter whose
type is inferred, but with the other parameters variadic.
Basically, I want to do this:
auto f(Ts..., Inferred)(Inferred inf){}
and call it with f!(X,Y,Z)(w) //inferred will be typeof(w), Ts...
== (X, Y, Z)
which I can't do because the variadic template args have to come
last.
Is there a way to change f so that the caller can use it like I
want? I tried this approach which didn't work.
template f(Ts...){
auto f(Inferred)(Inferred inf){}
}
I don't see a way to specify a variadic set of template args but
have one inferred. I could wrap the variadic args in another
template so f just takes 2 params, but I'd like to avoid that
because it makes the calling code more complicated.
Nov 07 2020
On Saturday, 7 November 2020 at 20:43:04 UTC, Ben Jones wrote:
I'm trying to write a function template with 1 parameter whose
type is inferred, but with the other parameters variadic.
Basically, I want to do this:
auto f(Ts..., Inferred)(Inferred inf){}
and call it with f!(X,Y,Z)(w) //inferred will be typeof(w),
Ts... == (X, Y, Z)
which I can't do because the variadic template args have to
come last.
Is there a way to change f so that the caller can use it like I
want? I tried this approach which didn't work.
template f(Ts...){
auto f(Inferred)(Inferred inf){}
}
I don't see a way to specify a variadic set of template args
but have one inferred. I could wrap the variadic args in
another template so f just takes 2 params, but I'd like to
avoid that because it makes the calling code more complicated.
template f(Ts...) {
auto f(Inferred)(Inferred inf) {
pragma(msg, Ts);
import std.stdio : writeln;
inf.writeln;
}
}
void main() {
f!(int, float, char)("Hello, world!");
}
https://run.dlang.io/is/e8FGrF
Nov 07 2020
On Saturday, 7 November 2020 at 21:04:19 UTC, starcanopy wrote:
void main() {
f!(int, float, char)("Hello, world!");
}
https://run.dlang.io/is/e8FGrF
Ah, I had discovered a different error when I tried that. Thanks!
Nov 07 2020








Ben Jones <fake fake.fake>