mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
cb99f65c96
Includes make_unique from C++14 and make_unique_default_init from C++20, because it doesn't require compiler support
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#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;
|