Listing 10
#include <memory>
#include <set>
#include <iostream>
using std::tr1::shared_ptr;
using std::set; using std::cout;
typedef shared_ptr<int> sp_t;
typedef set<sp_t> set_t;
int main()
{ // demonstrate shared_ptr as key
set_t set;
for (int i = 0; i < 10; ++i)
set.insert(sp_t(new int(i)));
sp_t first = *set.begin();
if (set.find(first) != set.end())
cout << "found shared_ptr holding " << *first << '\n';
else
cout << "didnt' find shared_ptr holding " << *first << '\n';
sp_t zero(new int(0));
if (set.find(zero) != set.end())
cout << "found shared_ptr holding " << *zero << '\n';
else
cout << "didnt' find shared_ptr holding " << *zero << '\n';
return 0;
}