Thanks! Indeed it would make sense but I really agree it seems unintuitive.<br><br>Adrien<br><br><div class="gmail_quote">On Wed, May 18, 2011 at 21:44, Steven Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com">schveiguy@yahoo.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Wed, 18 May 2011 15:11:56 -0400, Adrien Chauve <<a href="mailto:adrien.chauve@gmail.com" target="_blank">adrien.chauve@gmail.com</a>> wrote:<br>


<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br><div class="im">
anyone on the alias difference?<br>
</div></blockquote>
<br>
I have a feeling that alias needs to be a symbol, and int is a keyword.<br>
<br>
a template alias can be any symbol, including a variable, function, delegate, etc.<br>
<br>
Though it does seem unintuitive that a template alias parameter can be a custom type, but not a keyword type.  I would say that's a bug, but I'm not sure.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Sat, May 14, 2011 at 20:12, Adrien Chauve <<a href="mailto:adrien.chauve@gmail.com" target="_blank">adrien.chauve@gmail.com</a>>wrote:<br>
<br>
</div><div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I've been playing with templates and I get some (really dumb) questions.<br>
By the way, I'm using dmd 2.053 64 bits on linux 64 bits.<br>
<br>
<br>
First, I didn't really get the difference between an alias template and a<br>
type template when they are both instanciated with a type.<br>
For example:<br>
<br>
//////// File test1.d<br>
// alias<br>
template<br>
template Foo(alias<br>
X)<br>
{<br>
<br>
    alias X<br>
Y;<br>
}<br>
<br>
<br>
<br>
// type<br>
template<br>
<br>
template<br>
Foo2(X)<br>
{<br>
<br>
    alias X<br>
Y;<br>
}<br>
<br>
<br>
<br>
struct Bar<br>
{}<br>
<br>
<br>
void<br>
main()<br>
<br>
{<br>
<br>
    alias Foo!(Bar).Y BarAlias; //<br>
ok<br>
    alias Foo2!(int).Y IntAlias; //<br>
ok<br>
    alias Foo!(int).Y OtherIntAlias; //<br>
error<br>
}<br>
////// end of file test1.d<br>
<br>
I get the following error from dmd:<br>
test1.d(19): Error: template instance Foo!(int) does not match template<br>
declaration Foo(alias X)<br>
test1.d(19): Error: identifier 'Y' of 'Foo!(int).Y' is not defined<br>
<br>
Why do the two templates behave differently? Why does the alias template<br>
yield an error? What did I miss about alias templates?<br>
<br>
<br>
<br>
<br>
My second question is about using anonymous delegates in map and pipe. I<br>
tried the following code:<br>
<br>
//////// File test2.d<br>
import<br>
std.functional;<br>
<br>
import<br>
std.algorithm;<br>
<br>
<br>
<br>
unittest<br>
<br>
{<br>
<br>
    immutable auto x = [1, 2, 3,<br>
4];<br>
<br>
<br>
    alias map!((i){return 2*i;})<br>
mult2;<br>
    assert(equal(mult2(x),<br>
[2,4,6,8]));<br>
<br>
<br>
    alias pipe!(mult2)<br>
pipe_mult2;<br>
    assert(equal(pipe_mult2(x), [2,4,6,8])); // ok<br>
<br>
<br>
<br>
    alias pipe!(mult2, mult2) pipe_mult4;      // error<br>
<br>
    assert(equal(pipe_mult4(x),<br>
[4,8,12,16]));<br>
}<br>
<br>
<br>
<br>
void main(){}<br>
/////////// end of file test2.d<br>
<br>
and when compiling it with dmd -unittest test2.d I get:<br>
test2.d(368): Error: function<br>
test2.__unittest3.map!(__dgliteral1).map!(immutable(int[])).map is a nested<br>
function and cannot be accessed from doIt<br>
test2.d(368): Error: function<br>
test2.__unittest3.map!(__dgliteral1).map!(Result).map is a nested function<br>
and cannot be accessed from doIt<br>
<br>
So a single pipe!mult2 is ok but when a I put a second there's an error.<br>
What's also interesting is that all cases work fine when I use a named<br>
function instead of an anonymous delegate.<br>
<br>
I'm not sure to understand what's the error in compose (pipe uses compose).<br>
And the error returned by dmd is a bit strange because in no way test2.d<br>
has more than 20 lines (in fact line 368 is the first line of map in<br>
std/algorithm.d). Besides, without a template instanciation stack trace, I<br>
think it's a bit difficult to dive into template errors.<br>
<br>
<br>
Cheers,<br>
Adrien<br>
<br>
</blockquote></div></div></blockquote>
</blockquote></div><br>