diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b65dadc..99af4a08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/nana/config.hpp b/include/nana/config.hpp index e97c70f6..b580adb0 100644 --- a/include/nana/config.hpp +++ b/include/nana/config.hpp @@ -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) diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 30d87935..f10dbebc 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -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 +#include +#include +#include + +namespace std { + template struct _Unique_if { + typedef unique_ptr _Single_object; + }; + + template struct _Unique_if { + typedef unique_ptr _Unknown_bound; + }; + + template struct _Unique_if { + typedef void _Known_bound; + }; + + template + typename _Unique_if::_Single_object + make_unique(Args&&... args) { + return unique_ptr(new T(std::forward(args)...)); + } + + template + typename _Unique_if::_Unknown_bound + make_unique(size_t n) { + typedef typename remove_extent::type U; + return unique_ptr(new U[n]()); + } + + template + typename _Unique_if::_Known_bound + make_unique(Args&&...) = delete; +} +#endif //STD_make_unique_NOT_SUPPORTED + #endif //NANA_MACROS_HPP diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index ef8b18a0..3da06cf2 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -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( 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( bgcolor, fgcolor ) } //custom_format{ new format{ bgcolor, fgcolor } } {} cell& cell::operator=(const cell& rhs)