1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // type_traits
11
12 // is_same
13
14 #include <type_traits>
15
16 #include "test_macros.h"
17
18 template <class T, class U>
test_is_same()19 void test_is_same()
20 {
21 static_assert(( std::is_same<T, U>::value), "");
22 static_assert((!std::is_same<const T, U>::value), "");
23 static_assert((!std::is_same<T, const U>::value), "");
24 static_assert(( std::is_same<const T, const U>::value), "");
25 #if TEST_STD_VER > 14
26 static_assert(( std::is_same_v<T, U>), "");
27 static_assert((!std::is_same_v<const T, U>), "");
28 static_assert((!std::is_same_v<T, const U>), "");
29 static_assert(( std::is_same_v<const T, const U>), "");
30 #endif
31 }
32
33 template <class T, class U>
test_is_same_ref()34 void test_is_same_ref()
35 {
36 static_assert((std::is_same<T, U>::value), "");
37 static_assert((std::is_same<const T, U>::value), "");
38 static_assert((std::is_same<T, const U>::value), "");
39 static_assert((std::is_same<const T, const U>::value), "");
40 #if TEST_STD_VER > 14
41 static_assert((std::is_same_v<T, U>), "");
42 static_assert((std::is_same_v<const T, U>), "");
43 static_assert((std::is_same_v<T, const U>), "");
44 static_assert((std::is_same_v<const T, const U>), "");
45 #endif
46 }
47
48 template <class T, class U>
test_is_not_same()49 void test_is_not_same()
50 {
51 static_assert((!std::is_same<T, U>::value), "");
52 }
53
54 class Class
55 {
56 public:
57 ~Class();
58 };
59
main()60 int main()
61 {
62 test_is_same<int, int>();
63 test_is_same<void, void>();
64 test_is_same<Class, Class>();
65 test_is_same<int*, int*>();
66 test_is_same_ref<int&, int&>();
67
68 test_is_not_same<int, void>();
69 test_is_not_same<void, Class>();
70 test_is_not_same<Class, int*>();
71 test_is_not_same<int*, int&>();
72 test_is_not_same<int&, int>();
73 }
74