Range Redesign: Copy Semantics
victoroak
victoroak at victor.oak
Mon Jan 22 16:31:36 UTC 2024
On Sunday, 21 January 2024 at 05:00:31 UTC, Jonathan M Davis
wrote:
>
> [...]
>
>
I think one problem with just "next" as the api for an Input
Range is that currently I don't know any safe way to return a
reference to the item. If "next" returns a pointer we can't be
sure the backing data structure (a growable array like
std::vector for example) did not freed that memory yet but I
guess this is the same for any range right now.
Any way, it would be good to have an optimization for Nullable!T
or a different type that when T is nullable (e.g. classes or
pointers) it doesn't need a boolean flag but also loses the
ability to store null inside it.
That's one of the optimizations of "Option" in Rust, although in
Rust references can't be null so it's ok to do this.
More information about the Digitalmars-d
mailing list