Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 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_array |
| 13 | |
| 14 | #include <type_traits> |
Marshall Clow | 55d741c | 2015-11-10 15:48:23 +0000 | [diff] [blame] | 15 | #include <cstddef> // for std::nullptr_t |
Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 16 | #include "test_macros.h" |
| 17 | |
| 18 | template <class T> |
| 19 | void test_is_array() |
| 20 | { |
| 21 | static_assert( std::is_array<T>::value, ""); |
| 22 | static_assert( std::is_array<const T>::value, ""); |
| 23 | static_assert( std::is_array<volatile T>::value, ""); |
| 24 | static_assert( std::is_array<const volatile T>::value, ""); |
| 25 | #if TEST_STD_VER > 14 |
| 26 | static_assert( std::is_array_v<T>, ""); |
| 27 | static_assert( std::is_array_v<const T>, ""); |
| 28 | static_assert( std::is_array_v<volatile T>, ""); |
| 29 | static_assert( std::is_array_v<const volatile T>, ""); |
| 30 | #endif |
| 31 | } |
| 32 | |
| 33 | template <class T> |
| 34 | void test_is_not_array() |
| 35 | { |
| 36 | static_assert(!std::is_array<T>::value, ""); |
| 37 | static_assert(!std::is_array<const T>::value, ""); |
| 38 | static_assert(!std::is_array<volatile T>::value, ""); |
| 39 | static_assert(!std::is_array<const volatile T>::value, ""); |
| 40 | #if TEST_STD_VER > 14 |
| 41 | static_assert(!std::is_array_v<T>, ""); |
| 42 | static_assert(!std::is_array_v<const T>, ""); |
| 43 | static_assert(!std::is_array_v<volatile T>, ""); |
| 44 | static_assert(!std::is_array_v<const volatile T>, ""); |
| 45 | #endif |
| 46 | } |
| 47 | |
| 48 | class Empty |
| 49 | { |
| 50 | }; |
| 51 | |
| 52 | class NotEmpty |
| 53 | { |
| 54 | virtual ~NotEmpty(); |
| 55 | }; |
| 56 | |
| 57 | union Union {}; |
| 58 | |
| 59 | struct bit_zero |
| 60 | { |
| 61 | int : 0; |
| 62 | }; |
| 63 | |
| 64 | class Abstract |
| 65 | { |
| 66 | virtual ~Abstract() = 0; |
| 67 | }; |
| 68 | |
| 69 | enum Enum {zero, one}; |
Marshall Clow | 7490f53 | 2016-02-25 20:15:47 +0000 | [diff] [blame] | 70 | struct incomplete_type; |
Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 71 | |
| 72 | typedef void (*FunctionPtr)(); |
| 73 | |
| 74 | int main() |
| 75 | { |
| 76 | test_is_array<char[3]>(); |
| 77 | test_is_array<char[]>(); |
| 78 | test_is_array<Union[]>(); |
| 79 | |
| 80 | test_is_not_array<std::nullptr_t>(); |
| 81 | test_is_not_array<void>(); |
| 82 | test_is_not_array<int&>(); |
| 83 | test_is_not_array<int&&>(); |
| 84 | test_is_not_array<int*>(); |
| 85 | test_is_not_array<double>(); |
| 86 | test_is_not_array<const int*>(); |
| 87 | test_is_not_array<Enum>(); |
| 88 | test_is_not_array<Union>(); |
| 89 | test_is_not_array<FunctionPtr>(); |
| 90 | test_is_not_array<Empty>(); |
| 91 | test_is_not_array<bit_zero>(); |
| 92 | test_is_not_array<NotEmpty>(); |
Marshall Clow | 7490f53 | 2016-02-25 20:15:47 +0000 | [diff] [blame] | 93 | test_is_not_array<incomplete_type>(); // LWG#2581 |
Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 94 | } |