1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
23 template<typename C
, typename T
, typename U
>
24 concept comparable
= requires (const C
& cmp
, const T
& t
, const U
& u
) {
33 operator int() const { return 0; }
34 operator long*() const { return nullptr; }
37 // Not three-way-comparable because of ambiguous conversion to int or long*:
38 static_assert( ! std::three_way_comparable
<X
> );
40 // And therefore X is not three-way-comparable-with anything else
41 // (because std::three_way_comparable_with<X, Y> requires that both
42 // three_way_comparable<X> and three_way_comparable<Y> are true).
43 static_assert( ! std::three_way_comparable_with
<X
, long*> );
46 // But <=> is valid and resolves to a builtin operator comparing pointers:
47 [[maybe_unused
]] auto c
= &l
<=> x
;
49 // But LWG 3530 says std::compare_three_way should not be usable:
50 static_assert( ! comparable
<std::compare_three_way
, long*, X
> );
51 static_assert( ! comparable
<std::compare_three_way
, X
, long*> );