当前:

pragma(msg, typeid(int).toString); //

应该允许上面的编译.即编译时使用typeid.

template myFunc(Args...) {
static if (shouldReturnByRef!Args)//应按引用返回
    ref ReturnType myFunc(Args args) {
        ... //
    }//引用是函数的属性,不是返回类型的属性.
else // 非引用版本
    ReturnType myFunc(Args args) {
        ... // 
    }
}

这样:

auto foo(){ return typeid(int); }
static assert(is(__traits(typeFromId, foo())==int));

编译时映射类型标识,为其相应类型,是很有用的.
如下:

//CT和RT类型信息基类
immutable abstract class NewTypeInfo {
    size_t tsize();
}//不变的抽象基类,

//T实现
immutable class NewTypeInfoImpl(T) : NewTypeInfo {
    override size_t tsize() {
        return T.sizeof;
    }//继承
}

// 用__typeid!T 来取T的关联单件对象
@property immutable(NewTypeInfo) __typeid(T)() {
    static immutable singleton = new NewTypeInfoImpl!T;
    return singleton;
}

auto static_map_tf(alias F)(immutable NewTypeInfo[] types...)
{//不变,F为函数.
    typeof(F(types[0]))[] result;//声明类型
    result.length = types.length;
    foreach(i, t; types){
        result[i] = F(t);
    }
    return result;
}//不用写.

static assert(static_map_tf!(t => t.tsize)(__typeid!int, __typeid!ushort) == [4, 2]);//第1种
static assert([__typeid!int, __typeid!ushort].map!(t => t.tsize).equal([4, 2]));//这样也可以,第2种

void main() {}

嗯,是感觉很爽.类是引用类型.

auto invoke(alias fun, Args...)(Args args)
{
  static if(__traits(isStaticFunction, fun))
    return fun(args);
  else
    return __traits(child, args[0], fun)(args[1 .. $]);
}

就可以调用类的了.

struct Foo
{
  bool isValid(int a)
  {
    return a > 0;
  }
}

auto foo = Foo();
assert(invoke!isValid(foo, 3));