|
@ -1,14 +1,14 @@ |
|
|
/* |
|
|
/* |
|
|
* @Author: chenjingyu |
|
|
* @Author: chenjingyu |
|
|
* @Date: 2022-10-11 01:43:58 |
|
|
* @Date: 2022-10-11 01:43:58 |
|
|
* @LastEditTime: 2022-10-11 01:59:50 |
|
|
|
|
|
|
|
|
* @LastEditTime: 2022-10-11 02:32:15 |
|
|
* @Description: Memory operator |
|
|
* @Description: Memory operator |
|
|
* @FilePath: \CThreadPool\src\UtilsCtrl\UMemory.h |
|
|
|
|
|
|
|
|
* @FilePath: /CThreadPool/src/UtilsCtrl/UMemory.h |
|
|
*/ |
|
|
*/ |
|
|
#ifndef CGRAPH_UMEMORY_H |
|
|
#ifndef CGRAPH_UMEMORY_H |
|
|
#define CGRAPH_UMEMORY_H |
|
|
#define CGRAPH_UMEMORY_H |
|
|
|
|
|
|
|
|
#include <memory.h> |
|
|
|
|
|
|
|
|
#include <memory> |
|
|
#include <type_traits> |
|
|
#include <type_traits> |
|
|
#include "../CBasic/CBasicInclude.h" |
|
|
#include "../CBasic/CBasicInclude.h" |
|
|
|
|
|
|
|
@ -24,8 +24,6 @@ std::unique_ptr WrapUnique(T* ptr) { |
|
|
return std::unique_ptr<T>(ptr); |
|
|
return std::unique_ptr<T>(ptr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
namespace memory_internal { |
|
|
|
|
|
|
|
|
|
|
|
// Traits to select proper overload and return type for `absl::make_unique<>`. |
|
|
// Traits to select proper overload and return type for `absl::make_unique<>`. |
|
|
template <typename T> |
|
|
template <typename T> |
|
|
struct MakeUniqueResult { |
|
|
struct MakeUniqueResult { |
|
@ -40,32 +38,20 @@ struct MakeUniqueResult { |
|
|
using invalid = void; |
|
|
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> |
|
|
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)...)); |
|
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template <typename T> |
|
|
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> |
|
|
template <typename T, typename... Args> |
|
|
typename memory_internal::MakeUniqueResult<T>::invalid make_unique( |
|
|
|
|
|
|
|
|
typename MakeUniqueResult<T>::invalid make_unique( |
|
|
Args&&... /* args */) = delete; |
|
|
Args&&... /* args */) = delete; |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
CGRAPH_NAMESPACE_END |
|
|
CGRAPH_NAMESPACE_END |
|
|
|
|
|
|
|
|