#include <iostream>
#include <vector>
#include <memory>
using namespace std;

class Story
{
	int n;
public:
    Story(int n): n(n) { cout << "story #" << n << " created" << endl; }
    ~Story() { cout << "story #" << n << " destroyed" << endl; }
};

int main()
{
	vector<shared_ptr<Story>> list1, list2;

	cout << "creating #1 and adding to first list" << endl;
	list1.emplace_back(make_shared<Story>(1));
	cout << "copying #1 to second list" << endl;
	list2.push_back(list1[0]);
	cout << "creating #2" << endl;
	auto story2 = make_shared<Story>(2);
	cout << "adding #2 to the second list" << endl;
	list2.push_back(story2);
	cout << "removing first ptr to story #2" << endl;
	story2 = nullptr;
	cout << "removing second ptr to story #2, now it will be destroyed" << endl;
	list2.resize(1);
	cout << "clearing first list" << endl;
	list1.clear();
	cout << "clearing second list, now story #1 will be destroyed" << endl;
	list2.clear();
	cout << "done" << endl;
}