Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 19 | static_assert((std::is_same<T, U>::value), ""); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 20 | static_assert((!std::is_same<const T, U>::value), ""); |
| 21 | static_assert((!std::is_same<T, const U>::value), ""); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 22 | static_assert((std::is_same<const T, const U>::value), ""); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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 | } |