New C++17 backport: folly::enable_shared_from_this
Summary: C++14 has no direct means of creating a std::weak_ptr, one must always create a (temporary) std::shared_ptr first. C++17 adds weak_from_this() to std::enable_shared_from_this to avoid that overhead. Alas code that is meant to compile under different language versions cannot rely on std::enable_shared_from_this::weak_from_this(). This new utility class uses SFINAE to call std::enable_shared_from_this<T>::weak_from_this() if available. Falls back to std::enable_shared_from_this<T>::shared_from_this() otherwise. Use as a drop-in replacement for std::enable_shared_from_this where weak_from_this() is desired. Reviewed By: yfeldblum Differential Revision: D4616394 fbshipit-source-id: 73bf6cd8852d4a33478a9280cc69c81e7ea73423
Showing
Please register or sign in to comment