개요
예제
- 코드
#include <iostream>
#include <memory>
#include <set>
using namespace std;
int main() {
shared_ptr<int> p1(new int(10));
shared_ptr<int> p2(p1, new int(20));
set<shared_ptr<int>> valueBased;
valueBased.insert(p1);
valueBased.insert(p2);
cout << valueBased.size() << endl;
for (const auto &iter : valueBased) {
cout << *iter << endl;
}
cout << "------" << endl;
set<shared_ptr<int>, owner_less<shared_ptr<int>>> ownerBased;
ownerBased.insert(p1);
ownerBased.insert(p2);
cout << ownerBased.size() << endl;
for (const auto &iter : ownerBased) {
cout << *iter << endl;
}
return 0;
}
- 실행 결과