O'Reilly logo
  • Yang Wu thinks this is interesting:

std::weak_ptr<const Widget>> cache; auto objPtr = cache[id].lock();

From

Cover of Effective Modern C++

Note

Store the pointer that may be expired (dangled) instead.