mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04: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
2 changed files with 43 additions and 0 deletions
|
@ -431,6 +431,7 @@
|
||||||
<ClInclude Include="KeyMap.h" />
|
<ClInclude Include="KeyMap.h" />
|
||||||
<ClInclude Include="Log.h" />
|
<ClInclude Include="Log.h" />
|
||||||
<ClInclude Include="LogManager.h" />
|
<ClInclude Include="LogManager.h" />
|
||||||
|
<ClInclude Include="MakeUnique.h" />
|
||||||
<ClInclude Include="MathUtil.h" />
|
<ClInclude Include="MathUtil.h" />
|
||||||
<ClInclude Include="MemArena.h" />
|
<ClInclude Include="MemArena.h" />
|
||||||
<ClInclude Include="MemoryUtil.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…
Add table
Reference in a new issue