feat support make_unique for ptr
All checks were successful
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m32s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m19s

This commit is contained in:
tqcq 2024-03-24 11:26:28 +08:00
parent c43def9ae8
commit e170bdb974

View File

@ -2,6 +2,7 @@
#define SLED_MAKE_UNIQUE_H #define SLED_MAKE_UNIQUE_H
#pragma once #pragma once
#include <memory> #include <memory>
#include <type_traits>
namespace sled { namespace sled {
template<typename T, typename... Args> 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)...))); 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 }// namespace sled
#endif// SLED_MAKE_UNIQUE_H #endif// SLED_MAKE_UNIQUE_H