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 | template <class T> |
54 | struct OverloadTest |
55 | { |
56 | void fn(std::is_same<T, int>) { } |
57 | void fn(std::false_type) { } |
58 | void x() { fn(std::false_type()); } |
59 | }; |
60 | |
61 | class Class |
62 | { |
63 | public: |
64 | ~Class(); |
65 | }; |
66 | |
67 | int main(int, char**) |
68 | { |
69 | test_is_same<int, int>(); |
70 | test_is_same<void, void>(); |
71 | test_is_same<Class, Class>(); |
72 | test_is_same<int*, int*>(); |
73 | test_is_same_ref<int&, int&>(); |
74 | |
75 | test_is_not_same<int, void>(); |
76 | test_is_not_same<void, Class>(); |
77 | test_is_not_same<Class, int*>(); |
78 | test_is_not_same<int*, int&>(); |
79 | test_is_not_same<int&, int>(); |
80 | |
81 | OverloadTest<char> t; |
82 | (void)t; |
83 | |
84 | return 0; |
85 | } |
86 | |