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_assignable |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 16 | template <class T, class U> |
| 17 | void test_is_trivially_assignable() |
| 18 | { |
| 19 | static_assert(( std::is_trivially_assignable<T, U>::value), ""); |
| 20 | } |
| 21 | |
| 22 | template <class T, class U> |
| 23 | void test_is_not_trivially_assignable() |
| 24 | { |
| 25 | static_assert((!std::is_trivially_assignable<T, U>::value), ""); |
| 26 | } |
| 27 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 28 | struct A |
| 29 | { |
| 30 | }; |
| 31 | |
| 32 | struct B |
| 33 | { |
| 34 | void operator=(A); |
| 35 | }; |
| 36 | |
Marshall Clow | d132bf4 | 2014-09-22 23:58:00 +0000 | [diff] [blame] | 37 | struct C |
| 38 | { |
| 39 | void operator=(C&); // not const |
| 40 | }; |
| 41 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 42 | int main() |
| 43 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 44 | test_is_trivially_assignable<int&, int&> (); |
| 45 | test_is_trivially_assignable<int&, int> (); |
| 46 | test_is_trivially_assignable<int&, double> (); |
| 47 | |
| 48 | test_is_not_trivially_assignable<int, int&> (); |
| 49 | test_is_not_trivially_assignable<int, int> (); |
| 50 | test_is_not_trivially_assignable<B, A> (); |
| 51 | test_is_not_trivially_assignable<A, B> (); |
Marshall Clow | d132bf4 | 2014-09-22 23:58:00 +0000 | [diff] [blame] | 52 | test_is_not_trivially_assignable<C&, C&> (); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 53 | } |