feat support make_unique for ptr
This commit is contained in:
parent
c43def9ae8
commit
e170bdb974
@ -2,6 +2,7 @@
|
||||
#define SLED_MAKE_UNIQUE_H
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace sled {
|
||||
template<typename T, typename... Args>
|
||||
@ -11,5 +12,13 @@ MakeUnique(Args &&...args) -> std::unique_ptr<T>
|
||||
return std::move(std::unique_ptr<T>(new T(std::forward<Args>(args)...)));
|
||||
}
|
||||
|
||||
template<typename T, typename U = T>
|
||||
inline typename std::enable_if<!std::is_pointer<T>::value && !std::is_pointer<U>::value && std::is_base_of<T, U>::value,
|
||||
std::unique_ptr<T>>::type
|
||||
MakeUnique(U *ptr)
|
||||
{
|
||||
return std::move(std::unique_ptr<T>(ptr));
|
||||
}
|
||||
|
||||
}// namespace sled
|
||||
#endif// SLED_MAKE_UNIQUE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user