pytorch/torch/csrc/utils/memory.h
Nikita Shulga 6a39613f35 [BE] Make torch/csrc/jit/tensorexpr/ clang-tidy clean (#55628)
Summary:
Mostly auto-generated changes using
```
 python3 tools/clang_tidy.py -c build -x torch/csrc/jit/tensorexpr/eval.cpp -s
```
With following common patterns manually fixed
- Use ` = default` instead of `{}`
- deleted methods should be public
- Use pass-by-value + std::move instead of pass-by-reference+copy

Pull Request resolved: https://github.com/pytorch/pytorch/pull/55628

Reviewed By: walterddr

Differential Revision: D27655378

Pulled By: malfet

fbshipit-source-id: 92be87a08113435d820711103ea9b0364182c71a
2021-04-08 19:44:14 -07:00

42 lines
1.1 KiB
C++

#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