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:
cyy
2023-09-28 17:24:08 +00:00
committed by PyTorch MergeBot
parent 7f5737392d
commit 7f5fd92372
2 changed files with 0 additions and 42 deletions

View File

@ -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",

View File

@ -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