Spec Clarification: Template Alias Parameters

Steven Schveighoffer schveiguy at yahoo.com
Thu Oct 21 04:06:13 PDT 2010


On Wed, 20 Oct 2010 22:03:18 -0400, dsimcha <dsimcha at yahoo.com> wrote:

> Template alias parameters tend to do some strange stuff when used to  
> alias
> variables.  For example, this works:
>
> import std.algorithm, std.stdio;
>
> void main() {
>     uint[] arr = [1,2,3,4,5];
>     uint num = 3;
>
>     bool lessThanNum(uint x) { return x < num; }
>     writeln(filter!lessThanNum(arr));
> }
>
> This doesn't:
>
> import std.algorithm, std.stdio;
>
> class Class {
>     uint toAdd = 1;
>
>     uint doAdd(uint num) {
>         return num + toAdd;
>     }
>
>     void doMap() {
>         auto arr = [1,2,3,4,5];
>         auto m = map!doAdd(arr);
>     }
> }
>
> algorithm.d(132): Error: this for doAdd needs to be type Class not type
> Map!(doAdd,int[])

These might be related bug reports:

http://d.puremagic.com/issues/show_bug.cgi?id=3051
http://d.puremagic.com/issues/show_bug.cgi?id=3052

I'm almost positive I've seen that before in a bug report, but I couldn't  
find it.

-Steve


More information about the Digitalmars-d mailing list