c++ - Is erasing element after before_begin() defined in an empty std::forward_list? -


does code have defined behaviour in c++ standard library?

std::forward_list<t> list; list.erase_after(list.before_begin()); 

intuition no, haven't been able locate exact standards wording particular case.

the precondition on erase_after is:

iterator erase_after(const_iterator position);

requires: iterator following position dereferenceable.

so example has undefined behaviour, because list empty, list.before_begin() not incrementable, there no iterator following it.

if list has @ least 1 element list.erase_after(list.before_begin()) valid.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -