y3c-stl 0.3.3
Friendly C++ STL wrapper with automatic stacktrace
Loading...
Searching...
No Matches
vector-iter-erase.cc

‍example output:

y3c-stl terminated: undefined behavior detected (ub_invalid_iter)
at y3c::vector<int>::iterator::operator++(): this iterator is invalidated.
Stack trace (most recent call first):
#0 0x000055bcadd407a6 in main at /home/runner/work/y3c-stl/y3c-stl/build/../examples/vector-iter-erase.cc:5:69
3: int main() {
4: y3c::vector<int> a = {1, 2, 3, 4, 5};
5: for (y3c::vector<int>::iterator it = a.begin(); it < a.end(); ++it) {
6: if (unwrap(*it) == 3) {
7: a.erase(it);
array, vector など各種コンテナのイテレータ
Definition iterator.h:26
contiguous_iterator & operator++()
Definition iterator.h:130
可変長配列 (std::vector)
Definition vector.h:23
iterator erase(const_iterator pos, internal::skip_trace_tag={})
要素の削除
Definition vector.h:293
iterator end()
末尾要素を指すイテレータを取得
Definition vector.h:707
iterator begin()
先頭要素を指すイテレータを取得
Definition vector.h:673
Definition array.h:8
#include <y3c/vector>
int main() {
y3c::vector<int> a = {1, 2, 3, 4, 5};
for (y3c::vector<int>::iterator it = a.begin(); it < a.end(); ++it) {
if (unwrap(*it) == 3) {
a.erase(it);
}
}
}