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_copy_constructible |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 16 | template <class T> |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 17 | void test_is_copy_constructible() |
| 18 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 19 | static_assert( std::is_copy_constructible<T>::value, ""); |
| 20 | } |
| 21 | |
| 22 | template <class T> |
| 23 | void test_is_not_copy_constructible() |
| 24 | { |
| 25 | static_assert(!std::is_copy_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 | |
Howard Hinnant | 6063ec1 | 2011-05-13 14:08:16 +0000 | [diff] [blame] | 56 | class B |
| 57 | { |
| 58 | B(const B&); |
| 59 | }; |
| 60 | |
Marshall Clow | d132bf4 | 2014-09-22 23:58:00 +0000 | [diff] [blame] | 61 | struct C |
| 62 | { |
| 63 | C(C&); // not const |
| 64 | void operator=(C&); // not const |
| 65 | }; |
| 66 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 67 | int main() |
| 68 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 69 | test_is_copy_constructible<A>(); |
| 70 | test_is_copy_constructible<int&>(); |
| 71 | test_is_copy_constructible<Union>(); |
| 72 | test_is_copy_constructible<Empty>(); |
| 73 | test_is_copy_constructible<int>(); |
| 74 | test_is_copy_constructible<double>(); |
| 75 | test_is_copy_constructible<int*>(); |
| 76 | test_is_copy_constructible<const int*>(); |
| 77 | test_is_copy_constructible<NotEmpty>(); |
| 78 | test_is_copy_constructible<bit_zero>(); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 79 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 80 | test_is_not_copy_constructible<char[3]>(); |
| 81 | test_is_not_copy_constructible<char[]>(); |
| 82 | test_is_not_copy_constructible<void>(); |
| 83 | test_is_not_copy_constructible<Abstract>(); |
Marshall Clow | d132bf4 | 2014-09-22 23:58:00 +0000 | [diff] [blame] | 84 | test_is_not_copy_constructible<C>(); |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 85 | #if __has_feature(cxx_access_control_sfinae) |
| 86 | test_is_not_copy_constructible<B>(); |
| 87 | #endif |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 88 | } |