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_move_constructible |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
| 16 | template <class T> |
| 17 | void test_is_trivially_move_constructible() |
| 18 | { |
| 19 | static_assert( std::is_trivially_move_constructible<T>::value, ""); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | template <class T> |
| 23 | void test_has_not_trivial_move_constructor() |
| 24 | { |
| 25 | static_assert(!std::is_trivially_move_constructible<T>::value, ""); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | class Empty |
| 29 | { |
| 30 | }; |
| 31 | |
| 32 | class NotEmpty |
| 33 | { |
| 34 | public: |
| 35 | virtual ~NotEmpty(); |
| 36 | }; |
| 37 | |
| 38 | union Union {}; |
| 39 | |
| 40 | struct bit_zero |
| 41 | { |
| 42 | int : 0; |
| 43 | }; |
| 44 | |
| 45 | class Abstract |
| 46 | { |
| 47 | public: |
| 48 | virtual ~Abstract() = 0; |
| 49 | }; |
| 50 | |
| 51 | struct A |
| 52 | { |
| 53 | A(const A&); |
| 54 | }; |
| 55 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 56 | #if __has_feature(cxx_defaulted_functions) |
Howard Hinnant | 4300839 | 2012-02-24 23:32:26 +0000 | [diff] [blame] | 57 | |
| 58 | struct MoveOnly1 |
| 59 | { |
| 60 | MoveOnly1(MoveOnly1&&); |
| 61 | }; |
| 62 | |
| 63 | struct MoveOnly2 |
| 64 | { |
| 65 | MoveOnly2(MoveOnly2&&) = default; |
| 66 | }; |
| 67 | |
| 68 | #endif |
| 69 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 70 | int main() |
| 71 | { |
| 72 | test_has_not_trivial_move_constructor<void>(); |
| 73 | test_has_not_trivial_move_constructor<A>(); |
| 74 | test_has_not_trivial_move_constructor<Abstract>(); |
| 75 | test_has_not_trivial_move_constructor<NotEmpty>(); |
| 76 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 77 | test_is_trivially_move_constructible<Union>(); |
| 78 | test_is_trivially_move_constructible<Empty>(); |
| 79 | test_is_trivially_move_constructible<int>(); |
| 80 | test_is_trivially_move_constructible<double>(); |
| 81 | test_is_trivially_move_constructible<int*>(); |
| 82 | test_is_trivially_move_constructible<const int*>(); |
| 83 | test_is_trivially_move_constructible<bit_zero>(); |
Howard Hinnant | 4300839 | 2012-02-24 23:32:26 +0000 | [diff] [blame] | 84 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 85 | #if __has_feature(cxx_defaulted_functions) |
Howard Hinnant | 4300839 | 2012-02-24 23:32:26 +0000 | [diff] [blame] | 86 | static_assert(!std::is_trivially_move_constructible<MoveOnly1>::value, ""); |
| 87 | static_assert( std::is_trivially_move_constructible<MoveOnly2>::value, ""); |
| 88 | #endif |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 89 | } |