Commit e170bdb9 authored by tqcq's avatar tqcq
Browse files

feat support make_unique for ptr

parent c43def9a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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