mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
Add MakeUnique.h so make_unique is available without C++14
Includes make_unique from C++14 and make_unique_default_init from C++20, because it doesn't require compiler support
This commit is contained in:
parent
8643360438
commit
cb99f65c96
@ -431,6 +431,7 @@
|
||||
<ClInclude Include="KeyMap.h" />
|
||||
<ClInclude Include="Log.h" />
|
||||
<ClInclude Include="LogManager.h" />
|
||||
<ClInclude Include="MakeUnique.h" />
|
||||
<ClInclude Include="MathUtil.h" />
|
||||
<ClInclude Include="MemArena.h" />
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
|
42
Common/MakeUnique.h
Normal file
42
Common/MakeUnique.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
// Custom make_unique so that C++14 support will not be necessary for compilation
|
||||
template<class T, class... Args,
|
||||
typename std::enable_if<!std::is_array<T>::value, int>::type = 0>
|
||||
std::unique_ptr<T> make_unique(Args&&... args)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<class T,
|
||||
typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0, int>::type = 0>
|
||||
std::unique_ptr<T> make_unique(std::size_t size)
|
||||
{
|
||||
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
|
||||
}
|
||||
|
||||
template<class T, class... Args,
|
||||
typename std::enable_if<std::extent<T>::value != 0, int>::type = 0>
|
||||
void make_unique(Args&&... args) = delete;
|
||||
|
||||
|
||||
template<class T,
|
||||
typename std::enable_if<!std::is_array<T>::value, int>::type = 0>
|
||||
std::unique_ptr<T> make_unique_default_init()
|
||||
{
|
||||
return std::unique_ptr<T>(new T);
|
||||
}
|
||||
|
||||
template<class T,
|
||||
typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0, int>::type = 0>
|
||||
std::unique_ptr<T> make_unique_default_init(std::size_t size)
|
||||
{
|
||||
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]);
|
||||
}
|
||||
|
||||
template<class T, class... Args,
|
||||
typename std::enable_if<std::extent<T>::value != 0, int>::type = 0>
|
||||
void make_unique_default_init(Args&&... args) = delete;
|
Loading…
Reference in New Issue
Block a user