r/cpp • wx | soci | swig • Jun 17 '15

Standardizing Variant: Difficult Decisions

https://www.justsoftwaresolutions.co.uk/cplusplus/standardizing-variant.html
32 Upvotes

56 comments sorted by

View all comments

Show parent comment

2

u/STL MSVC STL Dev Jun 19 '15

Only end iterators are affected. The scenarios would be storing pairs of iterators representing ranges (which can easily involve the end), or storing iterators to elements that can sometimes represent "no element" without an additional bool/optional (you store end to represent it).

With container-internal sentinel nodes, the implementation simply invalidates end iterators during swapping and moving.

1

u/[deleted] Jun 19 '15 edited Jun 19 '15

I wonder if iterators of different types as proposed by /u/ericniebler could help here: end could return a sentinel for a doubly-linked list, whose operator!=(iterator, sentinel) checks if iterator points to a node, and if that is the case, if that node has a next element or not.

2

u/STL MSVC STL Dev Jun 19 '15

No, because end iterators wouldn't be decrementable. And what would happen if you incremented an ordinary iterator to the end?