to_weak_ptr
Declared in <folly/Memory.h>
template<typename T>
std::weak_ptr<T>
to_weak_ptr(std::shared_ptr<T> const& ptr);
Make a weak_ptr and return it from a shared_ptr without specifying the template type parameter and letting the compiler deduce it.
So you can write this:
auto wptr = to_weak_ptr(getSomethingShared<T>());
Instead of this:
auto wptr = weak_ptr<T>(getSomethingShared<T>());
Useful when T is long, such as:
using T = foobar::FooBarAsyncClient;
a weak_ptr observing ptr
| Name | Description |
|---|---|
| ptr | the shared_ptr to observe |