[iter] Check for more before forwarding/rewinding past ends

This commit is contained in:
Behdad Esfahbod 2019-05-11 11:54:30 -07:00
parent c1c122e7b3
commit 606841b070
2 changed files with 4 additions and 6 deletions

View File

@ -196,11 +196,11 @@ struct hb_iter_fallback_mixin_t
/* Advancing: Implement __next__(), or __forward__() if random-access. */
void __next__ () { *thiz() += 1; }
void __forward__ (unsigned n) { while (n--) ++*thiz(); }
void __forward__ (unsigned n) { while (*thiz() && n--) ++*thiz(); }
/* Rewinding: Implement __prev__() or __rewind__() if bidirectional. */
void __prev__ () { *thiz() -= 1; }
void __rewind__ (unsigned n) { while (n--) --*thiz(); }
void __rewind__ (unsigned n) { while (*thiz() && n--) --*thiz(); }
/* Range-based for: Implement __end__() if can be done faster,
* and operator!=. */

View File

@ -82,10 +82,8 @@ test_iterator_non_default_constructable (Iter it)
(void) _;
it += it.len ();
if (0)
it = it + 10;
if (0)
it = 10 + it;
it = it + 10;
it = 10 + it;
assert (*it == it[0]);