#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
struct Vehicle {
  static inline int alive = 0;
  std::string name;
  explicit Vehicle(std::string value) : name(std::move(value)) { ++alive; }
  ~Vehicle() { --alive; }
  Vehicle(const Vehicle &) = delete;
  Vehicle &operator=(const Vehicle &) = delete;
};
void check(bool condition) {
  if (!condition)
    throw std::runtime_error("Ownership check failed");
}
int main() {
  {
    auto owner = std::make_unique<Vehicle>("Cart");
    Vehicle &view = *owner;
    auto destination = std::move(owner);
    check(!owner && destination && Vehicle::alive == 1);
    check(view.name == "Cart");
    auto final_owner = std::move(destination);
    check(!destination && final_owner && Vehicle::alive == 1);
    final_owner.reset();
    check(Vehicle::alive == 0);
    check(Vehicle::alive == 0);
    // view is now dangling and must never be read.
  }
  check(Vehicle::alive == 0);
  std::cout << "ownership verified\n";
}
