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 template <class T, class U> 17 void test_is_same() 18 { 19 static_assert((std::is_same<T, U>::value), ""); 20 static_assert((!std::is_same<const T, U>::value), ""); 21 static_assert((!std::is_same<T, const U>::value), ""); 22 static_assert((std::is_same<const T, const U>::value), ""); 23 } 24 25 template <class T, class U> 26 void 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 34 template <class T, class U> 35 void test_is_not_same() 36 { 37 static_assert((!std::is_same<T, U>::value), ""); 38 } 39 40 class Class 41 { 42 public: 43 ~Class(); 44 }; 45 46 int 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 } 60