blob: 7250d6ca773005e2d8a22b7455ed1483efa82d1b [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// is_same
13
14#include <type_traits>
15
16template <class T, class U>
17void test_is_same()
18{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070019 static_assert((std::is_same<T, U>::value), "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +000020 static_assert((!std::is_same<const T, U>::value), "");
21 static_assert((!std::is_same<T, const U>::value), "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070022 static_assert((std::is_same<const T, const U>::value), "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +000023}
24
25template <class T, class U>
26void test_is_same_ref()
27{
28 static_assert((std::is_same<T, U>::value), "");
29 static_assert((std::is_same<const T, U>::value), "");
30 static_assert((std::is_same<T, const U>::value), "");
31 static_assert((std::is_same<const T, const U>::value), "");
32}
33
34template <class T, class U>
35void test_is_not_same()
36{
37 static_assert((!std::is_same<T, U>::value), "");
38}
39
40class Class
41{
42public:
43 ~Class();
44};
45
46int main()
47{
48 test_is_same<int, int>();
49 test_is_same<void, void>();
50 test_is_same<Class, Class>();
51 test_is_same<int*, int*>();
52 test_is_same_ref<int&, int&>();
53
54 test_is_not_same<int, void>();
55 test_is_not_same<void, Class>();
56 test_is_not_same<Class, int*>();
57 test_is_not_same<int*, int&>();
58 test_is_not_same<int&, int>();
59}