c3c
c3c copied to clipboard
Allow slicing of user defined containers?
// 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];
}