c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Allow slicing of user defined containers?

Open lerno opened this issue 2 years ago • 0 comments

// Supporting the full set.
macro Foo._slice(Foo* foo, a, b, $a_from_end, $b_from_end)
{
    $if ($a_from_end)
        $if ($b_from_end)
            return foo.values[^a..^b];
        $endif
        return foo.values[^a..b];
    $endif    
    $if ($b_from_end)
        return foo.values[a..^b];
    $endif
    return foo.values[a..b];    
}

// Not supporting reverse
macro Bar._slice(Bar *bar, a, b, $a_from_end, $b_from_end)
{
    $assert(!$a_from_end && !$b_from_end, "Slicing from the end is not possible for Bar types.");
    return bar.valyes[a..b];
}

lerno avatar Jul 06 '23 21:07 lerno