1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03, c++11, c++14, c++17 10 // UNSUPPORTED: libcpp-no-concepts 11 12 // template<class T> 13 // concept copyable = see below; 14 15 #include <concepts> 16 17 #include <deque> 18 #include <forward_list> 19 #include <list> 20 #include <map> 21 #include <memory> 22 #include <optional> 23 #include <unordered_map> 24 #include <vector> 25 26 #include "type_classification/copyable.h" 27 28 static_assert(std::copyable<int>); 29 static_assert(std::copyable<int volatile>); 30 static_assert(std::copyable<int*>); 31 static_assert(std::copyable<int const*>); 32 static_assert(std::copyable<int volatile*>); 33 static_assert(std::copyable<int volatile const*>); 34 static_assert(std::copyable<int (*)()>); 35 36 struct S {}; 37 static_assert(std::copyable<S>); 38 static_assert(std::copyable<int S::*>); 39 static_assert(std::copyable<int (S::*)()>); 40 static_assert(std::copyable<int (S::*)() noexcept>); 41 static_assert(std::copyable<int (S::*)() &>); 42 static_assert(std::copyable<int (S::*)() & noexcept>); 43 static_assert(std::copyable<int (S::*)() &&>); 44 static_assert(std::copyable<int (S::*)() && noexcept>); 45 static_assert(std::copyable<int (S::*)() const>); 46 static_assert(std::copyable<int (S::*)() const noexcept>); 47 static_assert(std::copyable<int (S::*)() const&>); 48 static_assert(std::copyable<int (S::*)() const & noexcept>); 49 static_assert(std::copyable<int (S::*)() const&&>); 50 static_assert(std::copyable<int (S::*)() const && noexcept>); 51 static_assert(std::copyable<int (S::*)() volatile>); 52 static_assert(std::copyable<int (S::*)() volatile noexcept>); 53 static_assert(std::copyable<int (S::*)() volatile&>); 54 static_assert(std::copyable<int (S::*)() volatile & noexcept>); 55 static_assert(std::copyable<int (S::*)() volatile&&>); 56 static_assert(std::copyable<int (S::*)() volatile && noexcept>); 57 static_assert(std::copyable<int (S::*)() const volatile>); 58 static_assert(std::copyable<int (S::*)() const volatile noexcept>); 59 static_assert(std::copyable<int (S::*)() const volatile&>); 60 static_assert(std::copyable<int (S::*)() const volatile & noexcept>); 61 static_assert(std::copyable<int (S::*)() const volatile&&>); 62 static_assert(std::copyable<int (S::*)() const volatile && noexcept>); 63 64 static_assert(std::copyable<std::vector<int> >); 65 static_assert(std::copyable<std::deque<int> >); 66 static_assert(std::copyable<std::forward_list<int> >); 67 static_assert(std::copyable<std::list<int> >); 68 static_assert(std::copyable<std::shared_ptr<std::unique_ptr<int> > >); 69 static_assert(std::copyable<std::optional<std::vector<int> > >); 70 static_assert(std::copyable<std::vector<int> >); 71 static_assert(std::copyable<std::vector<std::unique_ptr<int> > >); 72 73 static_assert(std::copyable<has_volatile_member>); 74 static_assert(std::copyable<has_array_member>); 75 76 // Not objects 77 static_assert(!std::copyable<void>); 78 static_assert(!std::copyable<int&>); 79 static_assert(!std::copyable<int const&>); 80 static_assert(!std::copyable<int volatile&>); 81 static_assert(!std::copyable<int const volatile&>); 82 static_assert(!std::copyable<int&&>); 83 static_assert(!std::copyable<int const&&>); 84 static_assert(!std::copyable<int volatile&&>); 85 static_assert(!std::copyable<int const volatile&&>); 86 static_assert(!std::copyable<int()>); 87 static_assert(!std::copyable<int (&)()>); 88 static_assert(!std::copyable<int[5]>); 89 90 // Not copy constructible or copy assignable 91 static_assert(!std::copyable<std::unique_ptr<int> >); 92 93 // Not assignable 94 static_assert(!std::copyable<int const>); 95 static_assert(!std::copyable<int const volatile>); 96 static_assert(std::copyable<const_copy_assignment const>); 97 static_assert(!std::copyable<volatile_copy_assignment volatile>); 98 static_assert(std::copyable<cv_copy_assignment const volatile>); 99 100 static_assert(!std::copyable<no_copy_constructor>); 101 static_assert(!std::copyable<no_copy_assignment>); 102 103 static_assert(std::is_copy_assignable_v<no_copy_assignment_mutable>); 104 static_assert(!std::copyable<no_copy_assignment_mutable>); 105 static_assert(!std::copyable<derived_from_noncopyable>); 106 static_assert(!std::copyable<has_noncopyable>); 107 static_assert(!std::copyable<has_const_member>); 108 static_assert(!std::copyable<has_cv_member>); 109 static_assert(!std::copyable<has_lvalue_reference_member>); 110 static_assert(!std::copyable<has_rvalue_reference_member>); 111 static_assert(!std::copyable<has_function_ref_member>); 112 113 static_assert( 114 !std::assignable_from<deleted_assignment_from_const_rvalue&, 115 deleted_assignment_from_const_rvalue const>); 116 static_assert(!std::copyable<deleted_assignment_from_const_rvalue>); 117 118 int main(int, char**) { return 0; } 119