1 #include <gtest/gtest.h> 3 #include <torch/csrc/utils/memory.h> 5 #include <c10/util/Optional.h> 8 explicit TestValue(
const int& x) : lvalue_(x) {}
9 explicit TestValue(
int&& x) : rvalue_(x) {}
15 TEST(MakeUniqueTest, ForwardRvaluesCorrectly) {
16 auto ptr = torch::make_unique<TestValue>(123);
17 ASSERT_FALSE(ptr->lvalue_.has_value());
18 ASSERT_TRUE(ptr->rvalue_.has_value());
19 ASSERT_EQ(*ptr->rvalue_, 123);
22 TEST(MakeUniqueTest, ForwardLvaluesCorrectly) {
24 auto ptr = torch::make_unique<TestValue>(x);
25 ASSERT_TRUE(ptr->lvalue_.has_value());
26 ASSERT_EQ(*ptr->lvalue_, 5);
27 ASSERT_FALSE(ptr->rvalue_.has_value());
30 TEST(MakeUniqueTest, CanConstructUniquePtrOfArray) {
31 auto ptr = torch::make_unique<int[]>(3);