File tree Expand file tree Collapse file tree 3 files changed +2865
-1
lines changed Expand file tree Collapse file tree 3 files changed +2865
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ list(APPEND ATen_CPU_TEST_SRCS
2929 ${CMAKE_CURRENT_SOURCE_DIR} /xla_tensor_test.cpp
3030 ${CMAKE_CURRENT_SOURCE_DIR} /tensor_iterator_test.cpp
3131 ${CMAKE_CURRENT_SOURCE_DIR} /cpu_generator_test.cpp
32- ${CMAKE_CURRENT_SOURCE_DIR} /pow_test.cpp)
32+ ${CMAKE_CURRENT_SOURCE_DIR} /pow_test.cpp
33+ ${CMAKE_CURRENT_SOURCE_DIR} /variant_test.cpp)
3334
3435list (APPEND ATen_CUDA_TEST_SRCS
3536 ${CMAKE_CURRENT_SOURCE_DIR} /cuda_integer_divider_test.cu
Original file line number Diff line number Diff line change 1+ #include < gtest/gtest.h>
2+
3+ #include < c10/util/variant.h>
4+
5+ namespace testns {
6+
7+ namespace enumtype {
8+ // NOTE: We need to provide the default constructor for each struct,
9+ // otherwise Clang 3.8 would complain:
10+ // ```
11+ // error: default initialization of an object of const type 'const enumtype::Enum1'
12+ // without a user-provided default constructor
13+ // ```
14+ struct Enum1 { Enum1() {} };
15+ struct Enum2 { Enum2() {} };
16+ struct Enum3 { Enum3() {} };
17+ } // namespace enumtype
18+
19+ const enumtype::Enum1 kEnum1 ;
20+ const enumtype::Enum2 kEnum2 ;
21+ const enumtype::Enum3 kEnum3 ;
22+
23+ } // namespace testns
24+
25+ std::string func (c10::variant<testns::enumtype::Enum1, testns::enumtype::Enum2, testns::enumtype::Enum3> v) {
26+ if (c10::get_if<testns::enumtype::Enum1>(&v)) {
27+ return " Enum1" ;
28+ } else if (c10::get_if<testns::enumtype::Enum2>(&v)) {
29+ return " Enum2" ;
30+ } else if (c10::get_if<testns::enumtype::Enum3>(&v)) {
31+ return " Enum3" ;
32+ } else {
33+ return " Unsupported enum" ;
34+ }
35+ }
36+
37+ TEST (VariantTest, Basic) {
38+ ASSERT_EQ (func (testns::kEnum1 ), " Enum1" );
39+ ASSERT_EQ (func (testns::kEnum2 ), " Enum2" );
40+ ASSERT_EQ (func (testns::kEnum3 ), " Enum3" );
41+ }
You can’t perform that action at this time.
0 commit comments