On Tuesday, 8 January 2013 at 09:59:26 UTC, Simen Kjaeraas wrote:
On 2013-55-08 09:01, monarch_dodra <monarchdo...@gmail.com>
wrote:
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?
A non-eponymous template is currently the only way to do this.
Strangely, this works:
alias fun2 = fun!("++a", "--a");
auto m = fun2!(ubyte)(1);
Nice!
And now, for the 1M$ question: Can I rely on this behavior, or is
this an accepts invalid...?