Create a weak pointer from a shared pointer.
Declared in <absl/memory/memory.h>
template<typename T>
std::weak_ptr<T>
WeakenPtr(std::shared_ptr<T> const& ptr);
Creates a weak pointer associated with a given shared pointer. The returned value is a std::weak_ptr of deduced type.
Example:
auto sp = std::make_shared<int>(10); auto wp = absl::WeakenPtr(sp); CHECK_EQ(sp.get(), wp.lock().get()); sp.reset(); CHECK(wp.lock() == nullptr);
A std::weak_ptr referring to the value owned by ptr.
| Name | Description |
|---|---|
| ptr | The shared pointer to observe. |