Thanks.. I am working on getting the code to work with unrolling an array:

module main;

import std.stdio, std.traits;

template tuple(args...)
{
    alias tuple = args;
}

template tUnrollArray(args...)
{
        static if (isArray!(typeof(args)))
        {
                pragma(msg, "isarray");
                static if (args.length > 1)
                {
                        pragma(msg, "unrolling");
                        alias tUnrollArray = tuple!(arg[0], args[1..$]);
                }
                else
                {
                        static if (args[0].length > 1)
                        {
                                pragma(msg, "1");
alias tUnrollArray = tuple!(args[0][0], tUnrollArray!(args[0][1..$]));
                        }
                        else
                        {
                                pragma(msg, "2");
                                alias tUnrollArray = tuple!(args[0][0]);
                        }
                }
        }
        else
                alias tUnrollArray = args;
}

void main(string[] argv)
{
        auto z = ["a", "b"];
        writeln(tUnrollArray!(["a", "b"]));
        writeln(tUnrollArray!(z));    // fails
        readln();
}


which seems to follow along the lines of your tuple reduce.

The problem is that I would like for it to unroll compile time known variables. I think we talked about that already and you said it wasn't a good idea because of potential infinite loops for some types of templates(which, I still think in most cases it should be ok, such as above.

Making z immutable does work but I don't get why making it static doesn't.

In any case, if the code looks correct I'll try and add the ability to have tupleReduce join elements that are arrays.

The alias stuff is starting to make some sense but having to do recursion for simple iterations isn't very fun ;/

Reply via email to