Specifying eponymous template "internal parameter"
monarch_dodra
monarchdodra at gmail.com
Tue Jan 8 00:55:15 PST 2013
Sometimes (especially in phobos), one defines a parametrized
template, that resolves to a templated function.
This is a nifty trick, because it allows specifying a vararg
before the current type parameter, eg:
//----
auto r = [1, 2, 3];
auto m = map!("++a", "--a")(r);
//----
As you can see, the template guessed the type of r, even though
we used a vararg. This would not have worked with a single
template function.
My question though: I have a similar use case, but I NEED to be
able to explicitly specify the type of r: as such:
//----
auto m = fun!("++a", "--a", ubyte)(1);
auto m = fun!("++a", "--a")!(ubyte)(1);
auto m = fun!("++a", "--a").fun!ubyte(1);
//----
None of them work. In this specific case, I *need* to specify
that 1 is of type ubyte, but I really can't do it :/
Simplified example: in my use case, it is a "immutable(int[])":
Failure to specify the type means the compiler strips tail
immutability...
The only workaround I can find to make such a thing, is to *not*
use eponymous temples, and explicitly call an inner function.
This is ugly as sin, and it makes specifying the internal
parameter mandatory.
Any thoughts?
More information about the Digitalmars-d-learn
mailing list