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_empty |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
| 16 | template <class T> |
| 17 | void test_is_empty() |
| 18 | { |
| 19 | static_assert( std::is_empty<T>::value, ""); |
| 20 | static_assert( std::is_empty<const T>::value, ""); |
| 21 | static_assert( std::is_empty<volatile T>::value, ""); |
| 22 | static_assert( std::is_empty<const volatile T>::value, ""); |
| 23 | } |
| 24 | |
| 25 | template <class T> |
| 26 | void test_is_not_empty() |
| 27 | { |
| 28 | static_assert(!std::is_empty<T>::value, ""); |
| 29 | static_assert(!std::is_empty<const T>::value, ""); |
| 30 | static_assert(!std::is_empty<volatile T>::value, ""); |
| 31 | static_assert(!std::is_empty<const volatile T>::value, ""); |
| 32 | } |
| 33 | |
| 34 | class Empty |
| 35 | { |
| 36 | }; |
| 37 | |
| 38 | class NotEmpty |
| 39 | { |
| 40 | virtual ~NotEmpty(); |
| 41 | }; |
| 42 | |
| 43 | union Union {}; |
| 44 | |
| 45 | struct bit_zero |
| 46 | { |
| 47 | int : 0; |
| 48 | }; |
| 49 | |
| 50 | int main() |
| 51 | { |
| 52 | test_is_not_empty<void>(); |
| 53 | test_is_not_empty<int&>(); |
| 54 | test_is_not_empty<int>(); |
| 55 | test_is_not_empty<double>(); |
| 56 | test_is_not_empty<int*>(); |
| 57 | test_is_not_empty<const int*>(); |
| 58 | test_is_not_empty<char[3]>(); |
Marshall Clow | e33e03e | 2014-09-02 16:19:38 +0000 | [diff] [blame] | 59 | test_is_not_empty<char[]>(); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 60 | test_is_not_empty<Union>(); |
| 61 | test_is_not_empty<NotEmpty>(); |
| 62 | |
| 63 | test_is_empty<Empty>(); |
| 64 | test_is_empty<bit_zero>(); |
| 65 | } |