Well, I did mention "Also, I didn't code the FunctionAttribute part, but that's just because it's late and I want to sleep". I even left a big "todo" in there :)

I've overlooked that. :)

Here is the complete code. If you have to improve something, say it please.
One last question: why 'ss' as function name? :o

[code]
template rvalue(alias fun) {
    private string ss() {
                enum Func = __traits(identifier, fun);
        enum Ret  = ReturnType!(fun).stringof;
                
        alias Args = ParameterTypeTuple!(fun);
        alias ParameterStorageClassTuple!(fun) pstc;
        enum names = [ParameterIdentifierTuple!(fun)];

        string s;
        s ~= Ret ~ " " ~ Func ~ "(";
        foreach(i, Type; Args[0 .. $]) {
if (pstc[i] & ParameterStorageClass.scope_) s ~= "scope ";
            if (pstc[i] & ParameterStorageClass.out_) s ~= "out ";
if (pstc[i] & ParameterStorageClass.lazy_) s ~= "lazy ";
                        
            s ~= Args[i].stringof ~ " ";
            s ~= names[i];
                        
            if (i + 1 != Args.length) s ~= ", ";
        }
        s ~= ")";
                
                auto funcAttr = functionAttributes!(fun);
                if (funcAttr & FunctionAttribute.pure_) s ~= " pure";
                if (funcAttr & FunctionAttribute.nothrow_) s ~= " nothrow";
                if (funcAttr & FunctionAttribute.ref_) s ~= " ref";
if (!isMutable!(typeof(fun))) s ~= " const"; // no idea why FunctionAttribute has no const...

        s ~= " {\n\treturn " ~ Func ~ "(";
        if (Args.length) {
            s ~= names[0];
            foreach(i, Type; Args[1 .. $]) {
                s ~= ", " ~ names[i + 1];
            }
        }
        s ~= ");\n}\n";
        return s;
    }
        
    enum rvalue = ss();
}
[/code]

Reply via email to