Debian Codegraph @

libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc

raw
1 // { dg-do compile { target { c++11 && c++17_down } } }
2 // Not valid in C++20, because TwistedLogic doesn't model boolean-testable.
3
4 // Copyright (C) 2014-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 <tuple>
22
23 // A type that is contextually convertible to bool but cannot be used with
24 // the usual logical operators, and/or/not.
25 struct TwistedLogic {
26 bool value;
27
28 explicit operator bool() const noexcept { return value; }
29 };
30
31 template<typename T>
32 bool operator&&(const T&, TwistedLogic) = delete;
33
34 template<typename T>
35 bool operator&&(TwistedLogic, const T&) = delete;
36
37 template<typename T>
38 bool operator||(const T&, TwistedLogic) = delete;
39
40 template<typename T>
41 bool operator||(TwistedLogic, const T&) = delete;
42
43 bool operator!(TwistedLogic) noexcept = delete;
44
45 struct Compares {};
46
47 TwistedLogic operator==(const Compares&, const Compares&) { return {true}; }
48 TwistedLogic operator<(const Compares&, const Compares&) { return {false}; }
49
50 auto a = std::make_tuple(nullptr, Compares{}, 2, 'U');
51 auto b = a == a;
52
53 auto c = std::make_tuple("", Compares{}, 2, 'U');
54 auto d = c < c;