On Tuesday, 19 July 2016 at 01:22:01 UTC, jmh530 wrote:
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);
}

auto bar(T...)(T x)
{
  static if (T.length == 1 && isTuple!(T[0]))
    return foo(x.expand);
  else
    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