diff --git a/src/UtilsCtrl/UMemory.h b/src/UtilsCtrl/UMemory.h index 95c94ef..1c145c1 100644 --- a/src/UtilsCtrl/UMemory.h +++ b/src/UtilsCtrl/UMemory.h @@ -1,14 +1,14 @@ /* * @Author: chenjingyu * @Date: 2022-10-11 01:43:58 - * @LastEditTime: 2022-10-11 01:59:50 + * @LastEditTime: 2022-10-11 02:32:15 * @Description: Memory operator - * @FilePath: \CThreadPool\src\UtilsCtrl\UMemory.h + * @FilePath: /CThreadPool/src/UtilsCtrl/UMemory.h */ #ifndef CGRAPH_UMEMORY_H #define CGRAPH_UMEMORY_H -#include +#include #include #include "../CBasic/CBasicInclude.h" @@ -24,8 +24,6 @@ std::unique_ptr WrapUnique(T* ptr) { return std::unique_ptr(ptr); } -namespace memory_internal { - // Traits to select proper overload and return type for `absl::make_unique<>`. template struct MakeUniqueResult { @@ -40,32 +38,20 @@ struct MakeUniqueResult { using invalid = void; }; -} // namespace memory_internal - -// gcc 4.8 has __cplusplus at 201301 but the libstdc++ shipped with it doesn't -// define make_unique. Other supported compilers either just define __cplusplus -// as 201103 but have make_unique (msvc), or have make_unique whenever -// __cplusplus > 201103 (clang). -#if (__cplusplus > 201103L || defined(_MSC_VER)) && \ - !(defined(__GLIBCXX__) && !defined(__cpp_lib_make_unique)) -using std::make_unique; -#else - template -typename memory_internal::MakeUniqueResult::scalar make_unique( - Args&&... args) { +typename MakeUniqueResult::scalar make_unique( + Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } template -typename memory_internal::MakeUniqueResult::array make_unique(size_t n) { - return std::unique_ptr(new typename absl::remove_extent_t[n]()); +typename MakeUniqueResult::array make_unique(size_t n) { + return std::unique_ptr(new typename std::remove_extent[n]()); } template -typename memory_internal::MakeUniqueResult::invalid make_unique( +typename MakeUniqueResult::invalid make_unique( Args&&... /* args */) = delete; -#endif CGRAPH_NAMESPACE_END diff --git a/tutorial.cpp b/tutorial.cpp index e1f9dbd..9ee7f3f 100644 --- a/tutorial.cpp +++ b/tutorial.cpp @@ -7,6 +7,7 @@ ***************************/ #include "src/CThreadPool.h" +#include "src/UtilsCtrl/UMemory.h" #include "MyFunction.h" @@ -123,7 +124,7 @@ void tutorial_threadpool_3(UThreadPoolPtr tp) { int main() { - auto pool = std::make_unique(); // 构造一个线程池类的智能指针 + auto pool = make_unique(); // 构造一个线程池类的智能指针 CGRAPH_ECHO("======== tutorial_threadpool_1 begin. ========"); tutorial_threadpool_1(pool.get());