/*
 * Copyright ©2026 Soham Pardeshi. All rights reserved.
 * Permission is hereby granted to students registered for University of
 * Washington CSE 333 for use solely during Summer Quarter 2026 for
 * purposes of the course. No other use, copying, distribution, or
 * modification is permitted without prior written consent. Copyrights
 * for third-party components of this work must be honored. Instructors
 * interested in reusing these course materials should contact the author.
 */

#include <cstdlib>
#include <iostream>

#include "ToyPtr.h"

// Why a naive smart pointer is not enough.
//
// Build and run under valgrind:
//   make toyuse && valgrind --leak-check=full ./toyuse
// You should see an "Invalid free() / delete" error: x and y both own the
// same int, so both destructors delete it (double free).
//
// The real question a smart pointer must answer is: WHO owns the object
// when the pointer is copied? unique_ptr answers "only one owner, copying
// is banned"; shared_ptr answers "many owners, reference count them".
int main(int argc, char** argv) {
  ToyPtr<int> x(new int(5));
  ToyPtr<int> y = x;  // shallow copy: x.ptr_ == y.ptr_

  std::cout << "*x = " << *x << ", *y = " << *y << std::endl;
  return EXIT_SUCCESS;  // both destructors run -> double delete
}