Error :: make_unique is not a member of 'std

I am trying to compile the following thread pool program hosted in a code review in order to test it.

https://codereview.stackexchange.com/questions/55100/platform-independant-thread-pool-v4

But I get errors

threadpool.hpp: In member function 'std::future<decltype (task((forward<Args>)(args)...))> threadpool::enqueue_task(Func&&, Args&& ...)': threadpool.hpp:94:28: error: 'make_unique' was not declared in this scope auto package_ptr = make_unique<task_package_impl<R, decltype(bound_task)>> (std::move(bound_task), std::move(promise)); ^ threadpool.hpp:94:81: error: expected primary-expression before '>' token auto package_ptr = make_unique<task_package_impl<R, decltype(bound_task)>>(std::move(bound_task), std::move(promise)); ^ main.cpp: In function 'int main()': main.cpp:9:17: error: 'make_unique' is not a member of 'std' auto ptr1 = std::make_unique<unsigned>(); ^ main.cpp:9:34: error: expected primary-expression before 'unsigned' auto ptr1 = std::make_unique<unsigned>(); ^ main.cpp:14:17: error: 'make_unique' is not a member of 'std' auto ptr2 = std::make_unique<unsigned>(); ^ main.cpp:14:34: error: expected primary-expression before 'unsigned' auto ptr2 = std::make_unique<unsigned>(); 
+70
c ++ c ++ 11 compiler-errors unique-ptr c ++ 14
Jul 07 '14 at 11:13
source share
5 answers

make_unique is an upcoming C ++ 14 feature and therefore may not be available in your compiler, even if it is C ++ 11.

However, you can easily do your own implementation:

 template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); } 

(FYI, here is the final version of make_unique , which was voted in C ++ 14. This includes additional functions to cover arrays, but the general idea remains the same.)

+121
Jul 07 '14 at 11:16
source share
β€” -

If you have the latest compiler, you can change the following in your build settings:

  C++ Language Dialect C++14[-std=c++14] 

This works for me.

+14
Feb 23 '16 at 4:55
source share

1.gcc version> = 5
2.CXXFLAGS + = -std = c ++ 14
3. #include & lt; memory & gt;

+4
Sep 30 '18 at 3:44
source share

This happens to me when working with Xcode (I use the latest version of Xcode in 2019 ...). I use CMake to integrate the assembly. Using the following directive in CMakeLists.txt fixed it for me:

set(CMAKE_CXX_STANDARD 14) .

Example:

 cmake_minimum_required(VERSION 3.14.0) set(CMAKE_CXX_STANDARD 14) # Rest of your declarations... 
0
Mar 26 '19 at 17:04
source share

In my case, I needed to update std = c ++

I mean, in my Gradle file it was

 android { ... defaultConfig { ... externalNativeBuild { cmake { cppFlags "-std=c++11", "-Wall" arguments "-DANDROID_STL=c++_static", "-DARCORE_LIBPATH=${arcore_libpath}/jni", "-DARCORE_INCLUDE=${project.rootDir}/app/src/main/libs" } } .... } 

I changed this line

 android { ... defaultConfig { ... externalNativeBuild { cmake { cppFlags "-std=c++17", "-Wall" <-- this number from 11 to 17 (or 14) arguments "-DANDROID_STL=c++_static", "-DARCORE_LIBPATH=${arcore_libpath}/jni", "-DARCORE_INCLUDE=${project.rootDir}/app/src/main/libs" } } .... } 

What is it...

0
Aug 29 '19 at 12:46
source share



All Articles