core: add make_shared(T&&) overload

Allows for code like this:

  auto p = make_shared(object());
This commit is contained in:
Tomasz Grabiec
2015-03-04 17:38:12 +01:00
committed by Avi Kivity
parent 83963b23d3
commit d674cd7deb

View File

@@ -69,6 +69,9 @@ lw_shared_ptr<T> make_lw_shared(T& a);
template <typename T, typename... A>
shared_ptr<T> make_shared(A&&... a);
template <typename T>
shared_ptr<T> make_shared(T&& a);
template <typename T, typename U>
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& p);
@@ -375,6 +378,9 @@ public:
template <typename U, typename... A>
friend shared_ptr<U> make_shared(A&&... a);
template <typename U>
friend shared_ptr<U> make_shared(U&& a);
template <typename V, typename U>
friend shared_ptr<V> static_pointer_cast(const shared_ptr<U>& p);
@@ -424,6 +430,14 @@ make_shared(A&&... a) {
return helper::make(std::forward<A>(a)...);
}
template <typename T>
inline
shared_ptr<T>
make_shared(T&& a) {
using helper = shared_ptr_make_helper<T, std::is_base_of<enable_shared_from_this<T>, T>::value>;
return helper::make(std::forward<T>(a));
}
template <typename T, typename U>
inline
shared_ptr<T>