std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]

jmh530 john.michael.hall at gmail.com
Sat Jun 20 23:16:19 UTC 2020


On Saturday, 20 June 2020 at 18:33:46 UTC, Steven Schveighoffer 
wrote:
> [snip]
>
> Sorry, this is not the same.
>
> Cursors are simply a way to refer to exactly one element, 
> instead of using a begin and end element like a traditional 
> container range would.
>
> The advantage is that removing the "end" element (that has 
> nothing to do with the range) won't invalidate the cursor.
>
> What I wanted was the functionality of C++ iterators without 
> the danger that comes with actually iterating them.
>
> -Steve

Andrei's proposal was for a function that returns true and fills 
the referred to variable and returns false otherwise. Cursors are 
obviously different, but they have a similarity in that a simple 
cursor, like below, has true/false behavior by storing it in 
empty.

struct Cursor(T) {
     T* ptr;
     bool empty = false;
}

That aspect of it was what I was thinking of. So for instance, if 
you have a struct that has a Cursor as a member, then you could 
do something like below.
bool fetchNext(ref T target) {
     cursor.popFront; //need to define popFront
     target = cursor.ptr;
     return cursor.empty;
}


More information about the Digitalmars-d mailing list