You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
973 B
C++
37 lines
973 B
C++
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#if __cplusplus <= 201103L
|
|
|
|
namespace {
|
|
template<class T>
|
|
struct is_unbound_array : std::false_type {};
|
|
|
|
template<class T>
|
|
struct is_unbound_array<T[]> : std::true_type {};
|
|
|
|
template<class T>
|
|
struct is_bound_array : std::false_type {};
|
|
|
|
template<class T, std::size_t N>
|
|
struct is_bound_array<T[N]> : std::true_type {};
|
|
}
|
|
|
|
namespace std {
|
|
template<typename T, typename... Args>
|
|
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type make_unique(Args&&... args) {
|
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
|
}
|
|
|
|
template<typename T>
|
|
typename std::enable_if<is_unbound_array<T>::value, std::unique_ptr<T>>::type make_unique(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<is_bound_array<T>::value>::type make_unique( Args&&... args ) = delete;
|
|
}
|
|
|
|
#endif
|