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 | // function |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
Eric Fiselier | 89465dc | 2015-02-18 16:31:46 +0000 | [diff] [blame] | 16 | using namespace std; |
| 17 | |
| 18 | class Class {}; |
| 19 | |
| 20 | enum Enum1 {}; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 21 | #if __cplusplus >= 201103L |
Eric Fiselier | 89465dc | 2015-02-18 16:31:46 +0000 | [diff] [blame] | 22 | enum class Enum2 : int {}; |
| 23 | #else |
| 24 | enum Enum2 {}; |
| 25 | #endif |
| 26 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 27 | template <class T> |
Eric Fiselier | 89465dc | 2015-02-18 16:31:46 +0000 | [diff] [blame] | 28 | void test() |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 29 | { |
| 30 | static_assert(!std::is_void<T>::value, ""); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 31 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | 79d8c99 | 2013-10-05 21:21:17 +0000 | [diff] [blame] | 32 | static_assert(!std::is_null_pointer<T>::value, ""); |
| 33 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 34 | static_assert(!std::is_integral<T>::value, ""); |
| 35 | static_assert(!std::is_floating_point<T>::value, ""); |
| 36 | static_assert(!std::is_array<T>::value, ""); |
| 37 | static_assert(!std::is_pointer<T>::value, ""); |
| 38 | static_assert(!std::is_lvalue_reference<T>::value, ""); |
| 39 | static_assert(!std::is_rvalue_reference<T>::value, ""); |
| 40 | static_assert(!std::is_member_object_pointer<T>::value, ""); |
| 41 | static_assert(!std::is_member_function_pointer<T>::value, ""); |
| 42 | static_assert(!std::is_enum<T>::value, ""); |
| 43 | static_assert(!std::is_union<T>::value, ""); |
| 44 | static_assert(!std::is_class<T>::value, ""); |
| 45 | static_assert( std::is_function<T>::value, ""); |
| 46 | } |
| 47 | |
Eric Fiselier | 89465dc | 2015-02-18 16:31:46 +0000 | [diff] [blame] | 48 | // Since we can't actually add the const volatile and ref qualifiers once |
| 49 | // later let's use a macro to do it. |
| 50 | #define TEST_REGULAR(...) \ |
| 51 | test<__VA_ARGS__>(); \ |
| 52 | test<__VA_ARGS__ const>(); \ |
| 53 | test<__VA_ARGS__ volatile>(); \ |
| 54 | test<__VA_ARGS__ const volatile>() |
| 55 | |
| 56 | |
| 57 | #define TEST_REF_QUALIFIED(...) \ |
| 58 | test<__VA_ARGS__ &>(); \ |
| 59 | test<__VA_ARGS__ const &>(); \ |
| 60 | test<__VA_ARGS__ volatile &>(); \ |
| 61 | test<__VA_ARGS__ const volatile &>(); \ |
| 62 | test<__VA_ARGS__ &&>(); \ |
| 63 | test<__VA_ARGS__ const &&>(); \ |
| 64 | test<__VA_ARGS__ volatile &&>(); \ |
| 65 | test<__VA_ARGS__ const volatile &&>() |
| 66 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 67 | |
| 68 | int main() |
| 69 | { |
Eric Fiselier | 89465dc | 2015-02-18 16:31:46 +0000 | [diff] [blame] | 70 | TEST_REGULAR( void () ); |
| 71 | TEST_REGULAR( void (int) ); |
| 72 | TEST_REGULAR( int (double) ); |
| 73 | TEST_REGULAR( int (double, char) ); |
| 74 | TEST_REGULAR( void (...) ); |
| 75 | TEST_REGULAR( void (int, ...) ); |
| 76 | TEST_REGULAR( int (double, ...) ); |
| 77 | TEST_REGULAR( int (double, char, ...) ); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 78 | #if __cplusplus >= 201103L |
Eric Fiselier | 89465dc | 2015-02-18 16:31:46 +0000 | [diff] [blame] | 79 | TEST_REF_QUALIFIED( void () ); |
| 80 | TEST_REF_QUALIFIED( void (int) ); |
| 81 | TEST_REF_QUALIFIED( int (double) ); |
| 82 | TEST_REF_QUALIFIED( int (double, char) ); |
| 83 | TEST_REF_QUALIFIED( void (...) ); |
| 84 | TEST_REF_QUALIFIED( void (int, ...) ); |
| 85 | TEST_REF_QUALIFIED( int (double, ...) ); |
| 86 | TEST_REF_QUALIFIED( int (double, char, ...) ); |
| 87 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 88 | } |