Fun With Generics, Class Templates and Static Ifs

bearophile bearophileHUGS at lycos.com
Thu Jun 4 10:12:34 PDT 2009


eris:

> class Rank(T, A...) : Ranker!(T) {

Better something like:
class Rank(TyItem, bool ascending=true) : Ranker!(TyItem) {
or something like that.
You have a single type, so the following too may be OK:
class Rank(T, bool ascending=true) : Ranker!(T) {
Using single upper case letters (as often done in C++) when you have more than one type is bad practice for me (yes, this is true for Phobos too). It's better the Pascal usage of giving them a meaningful name that starts with an upper case letter.


> In other words, rather than having to create a separate alias for each type create an alias like this:
> alias Rank!(T,-1) MinRank(T);
> alias Rank!(T, 1) MaxRank(T);
> I tried using this form, but I don't think the syntax is valid.

I think this works in D1:

template MinRank(T) {
    alias Rank!(T, true) MinRank;
}

template MaxRank(T) {
    alias Rank!(T, true) MaxRank;
}

Bye,
bearophile



More information about the Digitalmars-d mailing list