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_assignable |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
| 16 | struct A |
| 17 | { |
| 18 | }; |
| 19 | |
| 20 | struct B |
| 21 | { |
| 22 | void operator=(A); |
| 23 | }; |
| 24 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 25 | template <class T, class U> |
| 26 | void test_is_assignable() |
| 27 | { |
| 28 | static_assert(( std::is_assignable<T, U>::value), ""); |
| 29 | } |
| 30 | |
| 31 | template <class T, class U> |
| 32 | void test_is_not_assignable() |
| 33 | { |
| 34 | static_assert((!std::is_assignable<T, U>::value), ""); |
| 35 | } |
| 36 | |
Howard Hinnant | 01afa5c | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 37 | struct D; |
| 38 | |
Marshall Clow | f1d1087 | 2014-04-17 18:11:38 +0000 | [diff] [blame] | 39 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 01afa5c | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 40 | struct C |
| 41 | { |
| 42 | template <class U> |
| 43 | D operator,(U&&); |
| 44 | }; |
| 45 | |
| 46 | struct E |
| 47 | { |
| 48 | C operator=(int); |
| 49 | }; |
Marshall Clow | f1d1087 | 2014-04-17 18:11:38 +0000 | [diff] [blame] | 50 | #endif |
Howard Hinnant | 01afa5c | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 51 | |
Marshall Clow | 3a4964a | 2015-04-14 13:53:53 +0000 | [diff] [blame] | 52 | template <typename T> |
| 53 | struct X { T t; }; |
| 54 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 55 | int main() |
| 56 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 57 | test_is_assignable<int&, int&> (); |
| 58 | test_is_assignable<int&, int> (); |
| 59 | test_is_assignable<int&, double> (); |
| 60 | test_is_assignable<B, A> (); |
| 61 | test_is_assignable<void*&, void*> (); |
| 62 | |
| 63 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | f1d1087 | 2014-04-17 18:11:38 +0000 | [diff] [blame] | 64 | test_is_assignable<E, int> (); |
| 65 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 66 | test_is_not_assignable<int, int&> (); |
| 67 | test_is_not_assignable<int, int> (); |
| 68 | #endif |
| 69 | test_is_not_assignable<A, B> (); |
| 70 | test_is_not_assignable<void, const void> (); |
| 71 | test_is_not_assignable<const void, const void> (); |
| 72 | test_is_not_assignable<int(), int> (); |
Marshall Clow | 3a4964a | 2015-04-14 13:53:53 +0000 | [diff] [blame] | 73 | |
| 74 | // pointer to incomplete template type |
| 75 | test_is_assignable<X<D>*&, X<D>*> (); |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 76 | } |