absl::WeakenPtr

Create a weak pointer from a shared pointer.

Synopsis

Declared in <absl/memory/memory.h>

template<typename T>
std::weak_ptr<T>
WeakenPtr(std::shared_ptr<T> const& ptr);

Description

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);

Return Value

A std::weak_ptr referring to the value owned by ptr.

Parameters

NameDescription
ptrThe shared pointer to observe.