Range Redesign: Copy Semantics
Paul Backus
snarwin at gmail.com
Sun Jan 21 14:51:33 UTC 2024
On Sunday, 21 January 2024 at 05:00:31 UTC, Jonathan M Davis
wrote:
> From what I can see, the main negative is simply that you can't
> then write code that works on both a basic input range and a
> forward range (though you can obviously still create function
> overloads so that the caller can use either)
With the proposed design, it would be possible to implement
next() for forward ranges as a UFCS function:
auto next(FR)(FR fr)
if (std.v2.range.isForwardRange!FR)
{
if (fr.empty)
{
return Nullable!(ElementType!FR).init;
}
else
{
scope(success) fr.popFront;
return nullable(fr.front);
}
}
So, a function written to operate on basic input ranges would be
able to accept any kind of range, same as today.
More information about the Digitalmars-d
mailing list