In the code below, is it possible to combine both bar functions into one function (I just put some random foo function to get it to work)?

When I try to do it, I get errors that
no property 'expand' for type '(Tuple!(int, int))'
I think it has something to do with T... being considered a tuple. I also can't seem to do something using T.length because it is two regardless.

import std.typecons : isTuple, tuple;
import std.stdio : writeln;

auto foo(T...)(T x)
{
        T[0] y;
        foreach (i, e; x)
        {
                y += e;
        }
        return y;
}

auto bar(T)(T x)
{
        static if (isTuple!T)
        {
                return foo(x.expand);
        }
}

auto bar(T...)(T x)
{
        return foo(x);
}

void main()
{
        auto x = tuple(1, 2);
        auto y = bar(x);
        auto z = bar(x.expand);
        writeln(y);
        writeln(z);
}

Reply via email to