proxygen
folly::enable_shared_from_this< T > Class Template Reference

#include <EnableSharedFromThis.h>

Inheritance diagram for folly::enable_shared_from_this< T >:

Public Member Functions

constexpr enable_shared_from_this () noexcept=default
 
std::weak_ptr< Tweak_from_this () noexcept
 
std::weak_ptr< T const > weak_from_this () const noexcept
 

Private Member Functions

template<typename U >
auto weak_from_this_ (std::enable_shared_from_this< U > *base_ptr) noexcept-> decltype(base_ptr->weak_from_this())
 
template<typename U >
auto weak_from_this_ (std::enable_shared_from_this< U > const *base_ptr) const noexcept-> decltype(base_ptr->weak_from_this())
 
template<typename U >
std::weak_ptr< U > weak_from_this_ (...) noexcept
 
template<typename U >
std::weak_ptr< U const > weak_from_this_ (...) const noexcept
 

Detailed Description

template<typename T>
class folly::enable_shared_from_this< T >

Definition at line 55 of file EnableSharedFromThis.h.

Constructor & Destructor Documentation

Member Function Documentation

template<typename T >
std::weak_ptr<T> folly::enable_shared_from_this< T >::weak_from_this ( )
inlinenoexcept
Examples:
/facebook/proxygen/proxygen/folly/folly/memory/EnableSharedFromThis.h.

Definition at line 59 of file EnableSharedFromThis.h.

59  {
60  return weak_from_this_<T>(this);
61  }
template<typename T >
std::weak_ptr<T const> folly::enable_shared_from_this< T >::weak_from_this ( ) const
inlinenoexcept

Definition at line 63 of file EnableSharedFromThis.h.

63  {
64  return weak_from_this_<T>(this);
65  }
template<typename T >
template<typename U >
auto folly::enable_shared_from_this< T >::weak_from_this_ ( std::enable_shared_from_this< U > *  base_ptr) -> decltype(base_ptr->weak_from_this())
inlineprivatenoexcept
Examples:
/facebook/proxygen/proxygen/folly/folly/memory/EnableSharedFromThis.h.

Definition at line 72 of file EnableSharedFromThis.h.

73  {
74  return base_ptr->weak_from_this();
75  }
template<typename T >
template<typename U >
auto folly::enable_shared_from_this< T >::weak_from_this_ ( std::enable_shared_from_this< U > const *  base_ptr) const -> decltype(base_ptr->weak_from_this())
inlineprivatenoexcept

Definition at line 78 of file EnableSharedFromThis.h.

79  {
80  return base_ptr->weak_from_this();
81  }
template<typename T >
template<typename U >
std::weak_ptr<U> folly::enable_shared_from_this< T >::weak_from_this_ (   ...)
inlineprivatenoexcept

Definition at line 84 of file EnableSharedFromThis.h.

84  {
85  try {
86  return this->shared_from_this();
87  } catch (std::bad_weak_ptr const&) {
88  // C++17 requires that weak_from_this() on an object not owned by a
89  // shared_ptr returns an empty weak_ptr. Sadly, in C++14,
90  // shared_from_this() on such an object is undefined behavior, and there
91  // is nothing we can do to detect and handle the situation in a portable
92  // manner. But in case a compiler is nice enough to implement C++17
93  // semantics of shared_from_this() and throws a bad_weak_ptr, we catch it
94  // and return an empty weak_ptr.
95  return std::weak_ptr<U>{};
96  }
97  }
template<typename T >
template<typename U >
std::weak_ptr<U const> folly::enable_shared_from_this< T >::weak_from_this_ (   ...) const
inlineprivatenoexcept

Definition at line 100 of file EnableSharedFromThis.h.

100  {
101  try {
102  return this->shared_from_this();
103  } catch (std::bad_weak_ptr const&) {
104  return std::weak_ptr<U const>{};
105  }
106  }

The documentation for this class was generated from the following file: