#include <cstdlib>   // for EXIT_SUCCESS

#include <iostream>  // for std::cout, std::endl
#include <memory>    // for std::shared_ptr


int main(int argc, char** argv) {
  std::shared_ptr<int> x(new int(10));
  // x contains a pointer to an int and has reference count 1.
  std::cout << x.use_count() << std::endl;

  // temporary inner scope (!)
  {  
    // x and y now share the same pointer to an int, and they
    // share the reference count; the count is 2.
    std::shared_ptr<int> y(x);
    std::cout << y.use_count() << std::endl;
  }
  // y fell out of scope and was destroyed.  Therefore, the
  // reference count, which was previously seen by both x and y,
  // but now is seen only by x, is decremented to 1.
  std::cout << x.use_count() << std::endl;
  std::cout << x.unique() << std::endl;

  return EXIT_SUCCESS;
}