Range Redesign: Copy Semantics
Paul Backus
snarwin at gmail.com
Sun Jan 21 22:40:55 UTC 2024
On Sunday, 21 January 2024 at 18:26:37 UTC, Sebastiaan Koppe
wrote:
> What about:
>
> bool next(Callable)(Callable c) {
> if (empty)
> return false;
> c(front());
> popFront();
> return true;
> }
>
> It has the benefit of not needing to unbox a Nullable/Pointer.
If your concern is performance, an indirect function call is
going to hurt a lot more than a pointer dereference.
If your concern is aesthetics, dereferencing a pointer or
unboxing a Nullable is far less ugly than passing a callback.
// With pointer
while (auto p = r.next)
doStuffWith(*p);
// With callback
while (r.next((e) { doStuffWith(e); })) {}
More information about the Digitalmars-d
mailing list