[C++] Fix compilation with enable_shared_from_this

Summary:
Fixes issue with template argument deduction with enable_shared_from_this as argument
```
#include<memory>

template<class T>
void makeWeak(const std::shared_ptr<T>& x) {}

struct X : public std::enable_shared_from_this<X>{
};

void test() {
  X x
  makeWeak(x.shared_from_this()); // compilation failed here - it was unable to deduce template parameter of makeWeak
}
```

Reviewed By: jvillard

Differential Revision: D4414788

fbshipit-source-id: 4d19c53
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 4aeea1af3b
commit 11810d849b

@ -1,4 +1,5 @@
#define make_shared std__make_shared
#define enable_shared_from_this std__enable_shared_from_this
#define shared_ptr std__shared_ptr
#define unique_ptr std__unique_ptr
#define make_unique std__make_unique

@ -1,4 +1,5 @@
#undef make_shared
#undef enable_shared_from_this
#undef shared_ptr
#undef unique_ptr
#undef make_unique

@ -392,6 +392,17 @@ shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept {
return const_pointer_cast<T, U>((const std__shared_ptr<U>&)r);
}
template <class T>
class enable_shared_from_this : public std__enable_shared_from_this<T> {
public:
shared_ptr<T> shared_from_this() {
return std__enable_shared_from_this<T>::shared_from_this();
}
shared_ptr<T const> shared_from_this() const {
return std__enable_shared_from_this<T>::shared_from_this();
}
};
template <class T, class... Args>
shared_ptr<T> make_shared(Args&&... args) {
return shared_ptr<T>(new T(std::forward<Args>(args)...));

Loading…
Cancel
Save