STD_make_unique_NOT_SUPPORTED "Add support for make_unique<>()."
This commit is contained in:
parent
22ddc02184
commit
d5721fbe30
@ -4,6 +4,9 @@
|
||||
# Robert Hauck - Enable support for PNG/Freetype
|
||||
# Qiangqiang Wu - Add biicode support
|
||||
|
||||
option(CMAKE_STD_make_unique_NOT_SUPPORTED "Add support for make_unique<>().")
|
||||
#set(CMAKE_STD_make_unique_NOT_SUPPORTED OFF)
|
||||
|
||||
# set compile flags
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||
@ -96,6 +99,12 @@ endif()
|
||||
|
||||
|
||||
|
||||
# STD_make_unique_NOT_SUPPORTED
|
||||
if(CMAKE_STD_make_unique_NOT_SUPPORTED)
|
||||
add_definitions(-DSTD_make_unique_NOT_SUPPORTED)
|
||||
endif(CMAKE_STD_make_unique_NOT_SUPPORTED)
|
||||
|
||||
|
||||
set(NANA_SOURCE_DIR ${CMAKE_SOURCE_DIR}/source)
|
||||
set(NANA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -58,12 +58,12 @@ namespace nana
|
||||
|
||||
cell::cell(nana::string text, const format& fmt)
|
||||
: text(std::move(text)),
|
||||
custom_format(new format{ fmt }) //make_unique
|
||||
custom_format(std::make_unique<format>( fmt )) // or custom_format(new format{ fmt })
|
||||
{}
|
||||
|
||||
cell::cell(nana::string text, const ::nana::color& bgcolor, const ::nana::color& fgcolor)
|
||||
: text(std::move(text)),
|
||||
custom_format{ new format{ bgcolor, fgcolor } } //make_unique
|
||||
custom_format{std::make_unique<format>( bgcolor, fgcolor ) } //custom_format{ new format{ bgcolor, fgcolor } }
|
||||
{}
|
||||
|
||||
cell& cell::operator=(const cell& rhs)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user