Why tuples are not ranges?
Meta
jared771 at gmail.com
Thu Jun 28 18:11:24 UTC 2018
On Thursday, 28 June 2018 at 17:00:37 UTC, Mr.Bingo wrote:
> I mean, if you think about it, the memory layout of a tuple is
> sequential types:
>
> T1
> T2
> ...
>
> So, to popFront a tuple is just changing the starting offset.
You're right; it can definitely be done.
struct TupleRange(T...)
{
size_t index;
Tuple!T store;
@property length()
{
assert(index <= store.length);
return store.length - index;
}
Algebraic!T front()
{
assert(length > 0);
return typeof(return)(store[index]);
}
void popFront()
{
assert(length > 0);
index++;
}
}
More information about the Digitalmars-d-learn
mailing list