mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Reland use std::make_unique after internal changes (#109742)
check internal follow up of #109780 Pull Request resolved: https://github.com/pytorch/pytorch/pull/109742 Approved by: https://github.com/ezyang
This commit is contained in:
@ -71,7 +71,6 @@ def libtorch_generated_sources(gencode_pattern):
|
||||
|
||||
# copied from https://github.com/pytorch/pytorch/blob/f99a693cd9ff7a9b5fdc71357dac66b8192786d3/aten/src/ATen/core/CMakeLists.txt
|
||||
jit_core_headers = [
|
||||
"torch/csrc/utils/memory.h",
|
||||
"torch/csrc/Export.h",
|
||||
"torch/csrc/jit/frontend/source_range.h",
|
||||
"torch/csrc/jit/serialization/callstack_debug_info_serialization.h",
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace torch {
|
||||
|
||||
// Reference:
|
||||
// https://github.com/llvm-mirror/libcxx/blob/master/include/memory#L3091
|
||||
|
||||
template <typename T>
|
||||
struct unique_type_for {
|
||||
using value = std::unique_ptr<T>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
struct unique_type_for<T[]> {
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
using unbounded_array = std::unique_ptr<T[]>;
|
||||
};
|
||||
|
||||
template <typename T, size_t N>
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
struct unique_type_for<T[N]> {
|
||||
using bounded_array = void;
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
typename unique_type_for<T>::value make_unique(Args&&... args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename unique_type_for<T>::unbounded_array make_unique(size_t size) {
|
||||
using U = typename std::remove_extent<T>::type;
|
||||
return std::unique_ptr<T>(new U[size]());
|
||||
}
|
||||
|
||||
template <typename T, size_t N, typename... Args>
|
||||
typename unique_type_for<T>::bounded_array make_unique(Args&&...) = delete;
|
||||
} // namespace torch
|
||||
Reference in New Issue
Block a user