...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

再帰テンプレートのコツ

わかってきた!

// TLの中にあるTの個数を得る
template numType(T, TL...)
{
    template loop(int i, TList...)
    {
        alias Erase!(T, TList) ErasedTL;
        static if (is(ErasedTL == TList))
            alias i pre;
        else
            alias loop!(i+1, ErasedTL).pre pre;
    }
    enum numType = loop!(0,TL).pre;
}
pragma(msg, numType!(int,long,int,double,int).numType); // == 2

テンプレートのインスタンス化のあとに明示的に .numType とか .pre とかつければいいと思うよ!
numTypeの方は,本当はなくてもいいはずなんだけど.


最近はまちちゃんみたいな口調になってきたね! 気づいたかな?