On Friday, 3 May 2024 at 05:11:28 UTC, Salih Dincer wrote:

..
Wouldn't it be great if there was a feature that worked at runtime...

SDB@79

module m;
@safe:
private:
import std;

void main()
{
    auto myTuple = tuple(1, 2, 3, [1, 3], 5);
    int[] arrToSum;

    foreach(int i, val; myTuple.expand)
    {
        if(typeof(val).stringof == "int[]")
        {
            foreach(v; myTuple.expand[i..i+1])
                arrToSum ~= v;
        }
        else
        {
            arrToSum ~= val;
        }
    }

writefln("The total value of the tuples is: %s", arrToSum.sum); // 15
}

Reply via email to