1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // type_traits
10 
11 // is_same
12 
13 #include <type_traits>
14 
15 #include "test_macros.h"
16 
17 template <class T, class U>
18 void test_is_same()
19 {
20     static_assert(( std::is_same<T, U>::value), "");
21     static_assert((!std::is_same<const T, U>::value), "");
22     static_assert((!std::is_same<T, const U>::value), "");
23     static_assert(( std::is_same<const T, const U>::value), "");
24 #if TEST_STD_VER > 14
25     static_assert(( std::is_same_v<T, U>), "");
26     static_assert((!std::is_same_v<const T, U>), "");
27     static_assert((!std::is_same_v<T, const U>), "");
28     static_assert(( std::is_same_v<const T, const U>), "");
29 #endif
30 }
31 
32 template <class T, class U>
33 void test_is_same_ref()
34 {
35     static_assert((std::is_same<T, U>::value), "");
36     static_assert((std::is_same<const T, U>::value), "");
37     static_assert((std::is_same<T, const U>::value), "");
38     static_assert((std::is_same<const T, const U>::value), "");
39 #if TEST_STD_VER > 14
40     static_assert((std::is_same_v<T, U>), "");
41     static_assert((std::is_same_v<const T, U>), "");
42     static_assert((std::is_same_v<T, const U>), "");
43     static_assert((std::is_same_v<const T, const U>), "");
44 #endif
45 }
46 
47 template <class T, class U>
48 void test_is_not_same()
49 {
50     static_assert((!std::is_same<T, U>::value), "");
51 }
52 
53 class Class
54 {
55 public:
56     ~Class();
57 };
58 
59 int main(int, char**)
60 {
61     test_is_same<int, int>();
62     test_is_same<void, void>();
63     test_is_same<Class, Class>();
64     test_is_same<int*, int*>();
65     test_is_same_ref<int&, int&>();
66 
67     test_is_not_same<int, void>();
68     test_is_not_same<void, Class>();
69     test_is_not_same<Class, int*>();
70     test_is_not_same<int*, int&>();
71     test_is_not_same<int&, int>();
72 
73   return 0;
74 }
75