From b54e424d1bb6b223cccde1ddcbc82c9c18d5dcc9 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Tue, 20 Sep 2016 21:04:16 +0200 Subject: [PATCH] Implement make_unique, only require c++11 in CMakeLists (Fixes #235, Refs#167) --- CMakeLists.txt | 4 +--- base/threadpool.hpp | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a8ccaa8..4a923b40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,9 +31,7 @@ message(STATUS ${VULKAN_LIB}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -D_USE_MATH_DEFINES") add_definitions(-D_CRT_SECURE_NO_WARNINGS) -add_definitions(-std=c++14) -add_definitions(-std=c++0x) -add_definitions(-std=gnu++14) +add_definitions(-std=c++11) file(GLOB SOURCE *.cpp base/*.cpp) diff --git a/base/threadpool.hpp b/base/threadpool.hpp index 558f5484..c2feea11 100644 --- a/base/threadpool.hpp +++ b/base/threadpool.hpp @@ -12,6 +12,14 @@ #include #include +// make_unique is not available in C++11 +// Taken from Herb Sutter's blog (https://herbsutter.com/gotw/_102/) +template +std::unique_ptr make_unique(Args&& ...args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + namespace vkTools { class Thread @@ -95,7 +103,7 @@ namespace vkTools threads.clear(); for (auto i = 0; i < count; i++) { - threads.push_back(std::make_unique()); + threads.push_back(make_unique()); } }