STD_make_unique_NOT_SUPPORTED "Add support for make_unique<>()."
This commit is contained in:
@@ -82,7 +82,7 @@
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ == 4)
|
||||
#if ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ < 1))
|
||||
#if ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ <= 1))
|
||||
#define STD_THREAD_NOT_SUPPORTED
|
||||
|
||||
//boost.thread is preferred
|
||||
@@ -90,6 +90,10 @@
|
||||
//boost.thread will be replaced with meganz's mingw-std-threads.
|
||||
// https://github.com/meganz/mingw-std-threads
|
||||
//#define USE_github_com_meganz_mingw_std_threads
|
||||
#if !defined(STD_make_unique_NOT_SUPPORTED)
|
||||
#define STD_make_unique_NOT_SUPPORTED
|
||||
#endif //STD_make_unique_NOT_SUPPORTED
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(NANA_MINGW)
|
||||
|
||||
@@ -142,4 +142,44 @@ namespace nana
|
||||
#define NANA_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 )
|
||||
|
||||
|
||||
#if defined(STD_make_unique_NOT_SUPPORTED)
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3656.htm
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace std {
|
||||
template<class T> struct _Unique_if {
|
||||
typedef unique_ptr<T> _Single_object;
|
||||
};
|
||||
|
||||
template<class T> struct _Unique_if<T[]> {
|
||||
typedef unique_ptr<T[]> _Unknown_bound;
|
||||
};
|
||||
|
||||
template<class T, size_t N> struct _Unique_if<T[N]> {
|
||||
typedef void _Known_bound;
|
||||
};
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Single_object
|
||||
make_unique(Args&&... args) {
|
||||
return unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
typename _Unique_if<T>::_Unknown_bound
|
||||
make_unique(size_t n) {
|
||||
typedef typename remove_extent<T>::type U;
|
||||
return unique_ptr<T>(new U[n]());
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Known_bound
|
||||
make_unique(Args&&...) = delete;
|
||||
}
|
||||
#endif //STD_make_unique_NOT_SUPPORTED
|
||||
|
||||
#endif //NANA_MACROS_HPP
|
||||
|
||||
Reference in New Issue
Block a user