Preliminary submission - std.rational and std.typelist

Arlen arlen.ng at gmx.com
Sat Oct 6 12:48:40 PDT 2012


> ----- Original Message -----
> From: David Nadlinger
> Sent: 10/06/12 01:08 PM
> To: digitalmars-d at puremagic.com
> Subject: Re: Preliminary submission - std.rational and std.typelist
> 
> In my experience, these cases occur a lot less frequently than 
> one might think when first encountering the problem. The solution 
> I usually go for is to just define a ConfinedTuple (or something 
> like that) template:
> 
> ---
> template ConfinedTuple(T...) {
>  alias T Tuple;
> }
> 
> template SomeAlgorithm(alias A, alias B) {}
> ---
> 
> Then, call that one algorithm using 
> SomeAlgorithm!(ConfinedTuple!A, ConfinedTuple!B). At least to me, 
> it seems to be the better tradeoff compared to re-implementing 
> all the TypeTuple functionality for another compile-time tuple 
> type.
> 
> David

That does solve the initial problem, but it creates problems of its own.

The initial implementation of TypeList looked like this, which is same as your ConfinedTuple:

template TypeList(T...)
{
  alias T items;
}

but the problem with this is that it forces you to use 'alias' in the signature, which in turn causes code duplication later on.  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

Thanks,

Arlen


More information about the Digitalmars-d mailing list