Preliminary submission - std.rational and std.typelist

Arlen arlen.ng at gmx.com
Sat Oct 6 14:52:07 PDT 2012


On Sat, Oct 6, 2012 at 3:53 PM, David Nadlinger <see at klickverbot.at> wrote:
>
> On Saturday, 6 October 2012 at 20:00:47 UTC, Arlen wrote:
>>
>> You need both of these if you want, for example, fold to work with n-dimensional typelists:
>>
>> template Foldl(alias Fun, Z, alias TL) {  }
>> template Foldl(alias Fun, alias Z, alias TL) { } // when Z is a TypeList
>
>
> I'm not quite sure what you mean, as the parameter names are not quite telling. When would the first overload be needed? Actually, I'm reasonably sure that there is a solution to whatever problem you might be encountering – if maybe not obvious unless you have already learned the ins and outs of D metaprogramming the hard way. ;)
>

#1
template Foldl(alias Fun, Z, alias TL) {  }

This is called when dealing with 1-dimensional typelists.  For example:

alias Foldl!(MyFun, char, TL) R1;  // where TL is, e.g.,
TypeList!(int, char, double)

#2
template Foldl(alias Fun, alias Z, alias TL) { }

This is called when dealing with 2-dimensions or higher.  For example:

alias Foldl!(MyFun, TL1, TL2) R2;  // where TL1 is 1-dimensional,
e.g., TypeList!(int, char), and TL2 is 2-dimensional, e.g.,
TypeList!(TypeList!(int, char), TypeList!(float, double)).

I hope that's clear.

Another problem with this is that, when the time comes to implement
MyFun, chances are you will need to implement two versions of it, just
like the Foldl example above.  Making TypeList a struct instead of a
template fixed all these problem.  Maybe there another solution, but
that's what I could come up with.

>
> By the way, could you please fix the threading behavior of your mail client? At the moment, all of your replies create a new topic on the NG web interface (forum.dlang.org), which makes the conversation somewhat hard to follow.
>

Sorry about that.  I think it's fixed now.

> David


More information about the Digitalmars-d mailing list