| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// { dg-add-options no_pch } |
| 3 |
|
| 4 |
// Copyright (C) 2016-2025 Free Software Foundation, Inc. |
| 5 |
// |
| 6 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 7 |
// software; you can redistribute it and/or modify it under the |
| 8 |
// terms of the GNU General Public License as published by the |
| 9 |
// Free Software Foundation; either version 3, or (at your option) |
| 10 |
// any later version. |
| 11 |
// |
| 12 |
// This library is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU General Public License for more details. |
| 16 |
// |
| 17 |
// You should have received a copy of the GNU General Public License along |
| 18 |
// with this library; see the file COPYING3. If not see |
| 19 |
// <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
#include <type_traits> |
| 22 |
|
| 23 |
#ifndef __cpp_lib_is_swappable |
| 24 |
# error "Feature-test macro for is_swappable_with missing" |
| 25 |
#elif __cpp_lib_is_swappable != 201603 |
| 26 |
# error "Feature-test macro for is_swappable_with has wrong value" |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <testsuite_tr1.h> |
| 30 |
|
| 31 |
namespace funny { |
| 32 |
struct T0 {}; |
| 33 |
|
| 34 |
void swap(T0, T0); |
| 35 |
|
| 36 |
struct T1 {}; |
| 37 |
struct T2 {}; |
| 38 |
|
| 39 |
void swap(T1, T2); |
| 40 |
void swap(T2, T1); |
| 41 |
|
| 42 |
struct BoolLike {}; |
| 43 |
|
| 44 |
void swap(BoolLike, bool&); |
| 45 |
void swap(bool&, BoolLike); |
| 46 |
|
| 47 |
struct F0 {}; |
| 48 |
|
| 49 |
void swap(F0, F0) = delete; |
| 50 |
|
| 51 |
struct F1 {}; |
| 52 |
|
| 53 |
void swap(F0, F1) = delete; |
| 54 |
void swap(F1, F0) = delete; |
| 55 |
|
| 56 |
struct F2 {}; |
| 57 |
struct F3 {}; |
| 58 |
|
| 59 |
void swap(F2, F3); |
| 60 |
void swap(F3, F2) = delete; |
| 61 |
|
| 62 |
struct F4 |
| 63 |
{ |
| 64 |
friend void swap(F4, F4) = delete; |
| 65 |
}; |
| 66 |
} |
| 67 |
|
| 68 |
void test01() |
| 69 |
{ |
| 70 |
using std::is_swappable_with; |
| 71 |
using namespace __gnu_test; |
| 72 |
// Positive tests. |
| 73 |
static_assert(test_property<is_swappable_with, int&, int&>(true), ""); |
| 74 |
static_assert(test_property<is_swappable_with, funny::T0, |
| 75 |
funny::T0>(true), ""); |
| 76 |
static_assert(test_property<is_swappable_with, funny::T0, |
| 77 |
const funny::T0>(true), ""); |
| 78 |
static_assert(test_property<is_swappable_with, funny::T1, |
| 79 |
funny::T2>(true), ""); |
| 80 |
static_assert(test_property<is_swappable_with, funny::T2, |
| 81 |
funny::T1>(true), ""); |
| 82 |
static_assert(test_property<is_swappable_with, funny::BoolLike, |
| 83 |
bool&>(true), ""); |
| 84 |
static_assert(test_property<is_swappable_with, const funny::BoolLike, |
| 85 |
bool&>(true), ""); |
| 86 |
|
| 87 |
// Negative tests. |
| 88 |
static_assert(test_property<is_swappable_with, int, int>(false), ""); |
| 89 |
static_assert(test_property<is_swappable_with, int&, unsigned&>(false), ""); |
| 90 |
static_assert(test_property<is_swappable_with, const int&, |
| 91 |
const int&>(false), ""); |
| 92 |
static_assert(test_property<is_swappable_with, funny::F0, |
| 93 |
funny::F0>(false), ""); |
| 94 |
static_assert(test_property<is_swappable_with, funny::F0, |
| 95 |
const funny::F0>(false), ""); |
| 96 |
static_assert(test_property<is_swappable_with, funny::T0, |
| 97 |
funny::T1>(false), ""); |
| 98 |
static_assert(test_property<is_swappable_with, funny::F0, |
| 99 |
funny::F1>(false), ""); |
| 100 |
static_assert(test_property<is_swappable_with, funny::F0, |
| 101 |
const funny::F1>(false), ""); |
| 102 |
static_assert(test_property<is_swappable_with, const funny::F0, |
| 103 |
funny::F1>(false), ""); |
| 104 |
static_assert(test_property<is_swappable_with, funny::F2, |
| 105 |
funny::F3>(false), ""); |
| 106 |
static_assert(test_property<is_swappable_with, funny::F2, |
| 107 |
const funny::F3>(false), ""); |
| 108 |
static_assert(test_property<is_swappable_with, const funny::F2, |
| 109 |
funny::F3>(false), ""); |
| 110 |
static_assert(test_property<is_swappable_with, funny::F4, |
| 111 |
funny::F4>(false), ""); |
| 112 |
static_assert(test_property<is_swappable_with, funny::BoolLike, |
| 113 |
funny::BoolLike>(false), ""); |
| 114 |
} |