ashalkhakov / libatsc

ATS/C libraries
MIT License
3 stars 0 forks source link

External iterators #13

Open ashalkhakov opened 4 years ago

ashalkhakov commented 4 years ago

I think that for interests of flexibility it would be very nice to support "external iteration" kind of interface to iterating over an elements of collection. Currently e.g. slist implements some "internal iterators" (e.g. the foreach function template), but in this case we can't express some more advanced iteration patterns (without some unsafety).

An example of "advanced" iteration pattern is e.g. deleting or updating elements after N iteration steps (think of a "find-replace" operation in an dynamic array: pointer is bumped until an element satisfying a predicate is found, then this element might be deleted or updated).

For now we have the getref functions that allow a user to takeout a pointer to some element residing inside the collection. When is such a pointer safe to dereference? It depends the collection.

Try to implement C++-style iterators someday.