Debian Codegraph @

libstdc++-v3/testsuite/std/concepts/concepts.object/copyable.cc

raw
1 // Copyright (C) 2019-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do compile { target c++20 } }
19
20 #include <concepts>
21
22 static_assert( std::copyable<int> );
23 static_assert( std::copyable<int*> );
24 static_assert( ! std::copyable<int&> );
25 static_assert( ! std::copyable<void> );
26 static_assert( ! std::copyable<void()> );
27 static_assert( ! std::copyable<void() noexcept> );
28 static_assert( ! std::copyable<void() const> );
29
30 struct Trivial { };
31 static_assert( std::copyable<Trivial> );
32
33 struct NotTrivial
34 {
35 NotTrivial(int) { }
36 NotTrivial(const NotTrivial&) { }
37 NotTrivial& operator=(const NotTrivial&) { return *this; }
38 ~NotTrivial() { }
39 };
40 static_assert( std::copyable<NotTrivial> );
41
42 namespace N1
43 {
44 struct Immovable
45 {
46 Immovable() = default;
47 Immovable(Immovable&&) = delete;
48 };
49 }
50 static_assert( ! std::copyable<N1::Immovable> );
51
52 struct Movable
53 {
54 Movable() = default;
55 Movable(Movable&&) = default;
56 Movable& operator=(Movable&&) = default;
57 };
58 static_assert( ! std::copyable<Movable> );
59
60 struct MovableAndCopyAssignable
61 {
62 MovableAndCopyAssignable() = default;
63 MovableAndCopyAssignable(MovableAndCopyAssignable&&) = default;
64 MovableAndCopyAssignable& operator=(MovableAndCopyAssignable&&) = default;
65 MovableAndCopyAssignable& operator=(const MovableAndCopyAssignable&) = default;
66 };
67 static_assert( ! std::copyable<MovableAndCopyAssignable> );
68
69 struct MovableAndCopyConstructible
70 {
71 MovableAndCopyConstructible() = default;
72 MovableAndCopyConstructible(MovableAndCopyConstructible&&) = default;
73 MovableAndCopyConstructible(const MovableAndCopyConstructible&) = default;
74 MovableAndCopyConstructible& operator=(MovableAndCopyConstructible&&) = default;
75 };
76 static_assert( ! std::copyable<MovableAndCopyConstructible> );
77
78 namespace N2
79 {
80 struct Swappable
81 {
82 Swappable() = default;
83 Swappable(Swappable&&) = default;
84 friend void swap(Swappable&, Swappable&) { }
85 };
86 }
87 static_assert( ! std::copyable<N2::Swappable> );
88
89 struct NotAssignable
90 {
91 NotAssignable() = default;
92 NotAssignable(NotAssignable&&) = default;
93 NotAssignable& operator=(NotAssignable&&) = default;
94 NotAssignable(const NotAssignable&) = default;
95 NotAssignable& operator=(const NotAssignable&) = delete;
96 friend void swap(NotAssignable&, NotAssignable&) { }
97 };
98 static_assert( ! std::copyable<NotAssignable> );
99
100 struct NotSwappable
101 {
102 NotSwappable() = default;
103 NotSwappable(const NotSwappable&) = default;
104 NotSwappable& operator=(const NotSwappable&) = default;
105 };
106 void swap(NotSwappable&, NotSwappable&) = delete;
107 static_assert( std::copyable<NotSwappable> ); // ranges::swap still works!