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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -