std.typecons.Tupleが使えない。

D言語(v2.012)のstd.typecons.Tupleがだめ過ぎる。


ええと、std.typecons.Tupleってのは簡単に言うとboost::tupleみたいなもんです。
ところが、こいつには問題があって、むちゃくちゃ大雑把に実装を説明すると

struct Tuple(type){//説明のために1要素限定のTuple
	mixin(type.stringof ~ " _0;\n");
}

こんな感じに文字列mixinを使って変数を宣言しています。
が、type.stringofというのが呼び出されるのはstd.typecons.Tupleの中なので
std.typecons以外のモジュールで定義された型に触れません。
つまり

import std.typecons;
struct Hoge{}
Tuple!(Hoge) Huga;//Error: std.typeconsの中ではHogeは定義されていない

みたいな宣言を行うことが出来ません。
正直、この制限が鬱陶しかったので適当に修正加えてみました。


tupleImpl全書き換え

private template tupleImpl(uint index){}
private template tupleImpl(uint index,type,string name,T...){
    mixin tupleImpl!(index,type,T);
    mixin("alias _" ~ ToString!(index) ~ " " ~ name ~ ";\n");
}
private template tupleImpl(uint index,type,T...)
{
    enum string indexStr = ToString!(index);
    enum string decl = "type _"~indexStr~";"
        ~"\ntemplate field(int i : "~indexStr~") { alias _"~indexStr
        ~" field; }\n";
    mixin(decl);
    mixin tupleImpl!(index + 1, T);
}

struct Tuple直後のmixin(tupleImpl!(0, T).result);を変更

    mixin tupleImpl!(0, T);

なんかライブラリ周りで不満な点があったら、
自分の使うphobosだけ適当に修正加えてその場凌ぎをしてしまう癖が。

phobosは色々微妙なんだけど、Tangoとかは使う気が沸かないんだよなぁ