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_assignable 13 14 #include <type_traits> 15 16 template <class T> test_is_copy_assignable()17void test_is_copy_assignable() 18 { 19 static_assert(( std::is_copy_assignable<T>::value), ""); 20 } 21 22 template <class T> test_is_not_copy_assignable()23void test_is_not_copy_assignable() 24 { 25 static_assert((!std::is_copy_assignable<T>::value), ""); 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 struct A 46 { 47 A(); 48 }; 49 50 class B 51 { 52 B& operator=(const B&); 53 }; 54 55 struct C 56 { 57 void operator=(C&); // not const 58 }; 59 main()60int main() 61 { 62 test_is_copy_assignable<int> (); 63 test_is_copy_assignable<int&> (); 64 test_is_copy_assignable<A> (); 65 test_is_copy_assignable<bit_zero> (); 66 test_is_copy_assignable<Union> (); 67 test_is_copy_assignable<NotEmpty> (); 68 test_is_copy_assignable<Empty> (); 69 70 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 71 test_is_not_copy_assignable<const int> (); 72 test_is_not_copy_assignable<int[]> (); 73 test_is_not_copy_assignable<int[3]> (); 74 #endif 75 #if __has_feature(cxx_access_control_sfinae) 76 test_is_not_copy_assignable<B> (); 77 #endif 78 test_is_not_copy_assignable<void> (); 79 test_is_not_copy_assignable<C> (); 80 } 81