Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +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_trivially_copy_constructible |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
| 16 | template <class T> |
| 17 | void test_is_trivially_copy_constructible() |
| 18 | { |
| 19 | static_assert( std::is_trivially_copy_constructible<T>::value, ""); |
| 20 | static_assert( std::is_trivially_copy_constructible<const T>::value, ""); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | template <class T> |
| 24 | void test_has_not_trivial_copy_constructor() |
| 25 | { |
| 26 | static_assert(!std::is_trivially_copy_constructible<T>::value, ""); |
| 27 | static_assert(!std::is_trivially_copy_constructible<const T>::value, ""); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | class Empty |
| 31 | { |
| 32 | }; |
| 33 | |
| 34 | class NotEmpty |
| 35 | { |
| 36 | public: |
| 37 | virtual ~NotEmpty(); |
| 38 | }; |
| 39 | |
| 40 | union Union {}; |
| 41 | |
| 42 | struct bit_zero |
| 43 | { |
| 44 | int : 0; |
| 45 | }; |
| 46 | |
| 47 | class Abstract |
| 48 | { |
| 49 | public: |
| 50 | virtual ~Abstract() = 0; |
| 51 | }; |
| 52 | |
| 53 | struct A |
| 54 | { |
| 55 | A(const A&); |
| 56 | }; |
| 57 | |
| 58 | int main() |
| 59 | { |
| 60 | test_has_not_trivial_copy_constructor<void>(); |
| 61 | test_has_not_trivial_copy_constructor<A>(); |
| 62 | test_has_not_trivial_copy_constructor<Abstract>(); |
| 63 | test_has_not_trivial_copy_constructor<NotEmpty>(); |
| 64 | |
| 65 | test_is_trivially_copy_constructible<int&>(); |
| 66 | test_is_trivially_copy_constructible<Union>(); |
| 67 | test_is_trivially_copy_constructible<Empty>(); |
| 68 | test_is_trivially_copy_constructible<int>(); |
| 69 | test_is_trivially_copy_constructible<double>(); |
| 70 | test_is_trivially_copy_constructible<int*>(); |
| 71 | test_is_trivially_copy_constructible<const int*>(); |
| 72 | test_is_trivially_copy_constructible<bit_zero>(); |
| 73 | } |