#include <cstdlib>   // for EXIT_SUCCESS

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

using std::shared_ptr;
using std::weak_ptr;
using std::cout;
using std::endl;

int main(int argc, char** argv) {
  std::weak_ptr<int> w;

  {  // temporary inner scope
    std::shared_ptr<int> y(new int(10));
    w = y;  // assignment of weak_ptr takes a shared_ptr
    std::shared_ptr<int> x = w.lock();  // "promoted" shared_ptr

    std::cout << *x << " " << w.expired() << std::endl;
  }
  std::cout << w.expired() << std::endl;
  w.lock();  // returns a nullptr

  return EXIT_SUCCESS;
}