正常
WeakPtr: weak-pointer design, learned from Chromium
This directory implements a Chromium-style WeakPtr component and works through the modern C++ design of observing whether an object is still alive, without taking ownership. It sits alongside the OnceCallback series — the industrial-strength answer to the hand-rolled cancellation token from 01-4 is WeakPtr.
Full tutorial (full/)
For readers starting fresh, from weak-reference concepts and prerequisites through to a complete implementation.
Prerequisites (7 chapters):
- weak references and the lifetime puzzle
- intrusive refcounting and scoped_refptr
- std::atomic and memory_order
- sequences, SEQUENCE_CHECKER, and DCHECK/CHECK
- concepts and requires, advanced
- template friends and uintptr_t type erasure
- TRIVIAL_ABI and trivial relocatability
Hands-on (6 chapters):
- motivation and API design
- core skeleton and the control block
- WeakPtrFactory and the last-member idiom
- sequence affinity and lazy binding
- callback integration — closing OnceCallback's loop
- testing and performance
Hands-on design guide (hands_on/)
For readers comfortable with C++ templates and concurrency, a quick walkthrough of the design motivation, implementation, and testing: