| 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::movable<int> ); |
| 23 |
static_assert( std::movable<int*> ); |
| 24 |
static_assert( ! std::movable<int&> ); |
| 25 |
static_assert( ! std::movable<void> ); |
| 26 |
static_assert( ! std::movable<void()> ); |
| 27 |
static_assert( ! std::movable<void() noexcept> ); |
| 28 |
static_assert( ! std::movable<void() const> ); |
| 29 |
|
| 30 |
struct Trivial { }; |
| 31 |
static_assert( std::movable<Trivial> ); |
| 32 |
|
| 33 |
struct NotTrivial |
| 34 |
{ |
| 35 |
NotTrivial(int) { } |
| 36 |
NotTrivial(NotTrivial&&) { } |
| 37 |
NotTrivial& operator=(NotTrivial&&) { return *this; } |
| 38 |
~NotTrivial() { } |
| 39 |
}; |
| 40 |
static_assert( std::movable<NotTrivial> ); |
| 41 |
|
| 42 |
namespace N1 |
| 43 |
{ |
| 44 |
struct Immovable |
| 45 |
{ |
| 46 |
Immovable() = default; |
| 47 |
Immovable(Immovable&&) = delete; |
| 48 |
}; |
| 49 |
} |
| 50 |
static_assert( ! std::movable<N1::Immovable> ); |
| 51 |
|
| 52 |
namespace N2 |
| 53 |
{ |
| 54 |
struct Swappable |
| 55 |
{ |
| 56 |
Swappable() = default; |
| 57 |
Swappable(Swappable&&) = delete; |
| 58 |
Swappable& operator=(Swappable&&) = default; |
| 59 |
friend void swap(Swappable&, Swappable&) { } |
| 60 |
}; |
| 61 |
} |
| 62 |
static_assert( ! std::movable<N2::Swappable> ); |
| 63 |
|
| 64 |
struct NotAssignable |
| 65 |
{ |
| 66 |
NotAssignable() = default; |
| 67 |
NotAssignable(NotAssignable&&) = default; |
| 68 |
NotAssignable& operator=(NotAssignable&&) = delete; |
| 69 |
friend void swap(NotAssignable&, NotAssignable&) { } |
| 70 |
}; |
| 71 |
static_assert( ! std::movable<NotAssignable> ); |
| 72 |
|
| 73 |
struct NotSwappable |
| 74 |
{ |
| 75 |
NotSwappable() = default; |
| 76 |
NotSwappable(NotSwappable&&) = default; |
| 77 |
NotSwappable& operator=(NotSwappable&&) = default; |
| 78 |
}; |
| 79 |
void swap(NotSwappable&, NotSwappable&) = delete; |
| 80 |
static_assert( std::movable<NotSwappable> ); // ranges::swap still works! |