確認環境
$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.調査
test.cpp
#include <bits/stdc++.h>
using namespace std;
multiset<int> init() {
multiset<int> s;
s.insert(2);
s.insert(3);
s.insert(2);
s.insert(1);
s.insert(2);
return s;
}
void display(multiset<int> s) {
for (auto v : s) {
cout << v << " ";
}
cout << endl;
}
int main() {
multiset<int> s = init();
cout << "【ケース1】" << endl;
cout << "変更前" << endl;
display(s);
// 3つとも消えてしまう
s.erase(2);
cout << "変更後" << endl;
display(s);
cout << "---" << endl;
cout << "【ケース2】" << endl;
cout << "変更前" << endl;
s = init();
display(s);
cout << typeid(s.find(2)).name() << endl;
s.erase(s.find(2));
cout << "変更後" << endl;
display(s);
cout << "---" << endl;
cout << "【ケース3】" << endl;
cout << "変更前" << endl;
s = init();
display(s);
auto iter = s.lower_bound(2);
cout << typeid(iter).name() << endl;
s.erase(iter);
cout << "変更後" << endl;
display(s);
}出力結果
【ケース1】
変更前
1 2 2 2 3
変更後
1 3
---
【ケース2】
変更前
1 2 2 2 3
St23_Rb_tree_const_iteratorIiE
変更後
1 2 2 3
---
【ケース3】
変更前
1 2 2 2 3
St23_Rb_tree_const_iteratorIiE
変更後
1 2 2 3