Browse Source

Fixed:修复一些BUG;

chenjingyu 2 years ago
parent
commit
748ca40c98
2 changed files with 10 additions and 23 deletions
  1. +8
    -22
      src/UtilsCtrl/UMemory.h
  2. +2
    -1
      tutorial.cpp

+ 8
- 22
src/UtilsCtrl/UMemory.h View File

@ -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 <memory.h>
#include <memory>
#include <type_traits>
#include "../CBasic/CBasicInclude.h"
@ -24,8 +24,6 @@ std::unique_ptr WrapUnique(T* ptr) {
return std::unique_ptr<T>(ptr);
}
namespace memory_internal {
// Traits to select proper overload and return type for `absl::make_unique<>`.
template <typename T>
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 T, typename... Args>
typename memory_internal::MakeUniqueResult<T>::scalar make_unique(
Args&&... args) {
typename MakeUniqueResult<T>::scalar make_unique(
Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <typename T>
typename memory_internal::MakeUniqueResult<T>::array make_unique(size_t n) {
return std::unique_ptr<T>(new typename absl::remove_extent_t<T>[n]());
typename MakeUniqueResult<T>::array make_unique(size_t n) {
return std::unique_ptr<T>(new typename std::remove_extent<T>[n]());
}
template <typename T, typename... Args>
typename memory_internal::MakeUniqueResult<T>::invalid make_unique(
typename MakeUniqueResult<T>::invalid make_unique(
Args&&... /* args */) = delete;
#endif
CGRAPH_NAMESPACE_END

+ 2
- 1
tutorial.cpp View File

@ -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<UThreadPool>(); // 构造一个线程池类的智能指针
auto pool = make_unique<UThreadPool>(); // 构造一个线程池类的智能指针
CGRAPH_ECHO("======== tutorial_threadpool_1 begin. ========");
tutorial_threadpool_1(pool.get());

Loading…
Cancel
Save