]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do compile { target c++14 } } |
d081231a | 2 | |
a945c346 | 3 | // Copyright (C) 2013-2024 Free Software Foundation, Inc. |
d081231a JW |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | // 20.3.3 Comparisons | |
21 | ||
22 | #include <functional> | |
23 | ||
24 | struct R { }; | |
25 | ||
26 | struct L | |
27 | { | |
28 | L operator+(const R&) const { return *this; } | |
29 | L operator-(const R&) const { return *this; } | |
30 | L operator*(const R&) const { return *this; } | |
31 | L operator/(const R&) const { return *this; } | |
32 | L operator%(const R&) const { return *this; } | |
33 | L operator-() const { return *this; } | |
34 | ||
35 | bool operator==(const R&) const { return true; } | |
36 | bool operator!=(const R&) const { return false; } | |
37 | bool operator<(const R&) const { return false; } | |
38 | bool operator<=(const R&) const { return true; } | |
39 | bool operator>(const R&) const { return false; } | |
40 | bool operator>=(const R&) const { return true; } | |
41 | ||
42 | bool operator&&(const R&) const { return true; } | |
43 | bool operator||(const R&) const { return true; } | |
44 | bool operator!() const { return false; } | |
45 | ||
46 | int operator&(const R&) const { return 1; } | |
47 | int operator|(const R&) const { return 1; } | |
48 | int operator^(const R&) const { return 0; } | |
49 | int operator~() const { return 0; } | |
50 | }; | |
51 | ||
52 | L l; | |
53 | R r; | |
54 | ||
55 | // test unary function objects | |
56 | template<typename F, typename Check = typename F::is_transparent> | |
57 | bool | |
58 | test1(F f) | |
59 | { | |
60 | f(l); | |
61 | return true; | |
62 | } | |
63 | ||
64 | // test binary function objects | |
65 | template<typename F, typename Check = typename F::is_transparent> | |
66 | bool | |
67 | test2(F f) | |
68 | { | |
69 | f(l, r); | |
70 | return true; | |
71 | } | |
72 | ||
73 | auto plus = test2( std::plus<>() ); | |
74 | auto minus = test2( std::minus<>() ); | |
75 | auto multiplies = test2( std::multiplies<>() ); | |
76 | auto divides = test2( std::divides<>() ); | |
77 | auto modulus = test2( std::modulus<>() ); | |
78 | auto negate = test1( std::negate<>() ); | |
79 | ||
80 | auto equal_to = test2( std::equal_to<>() ); | |
81 | auto not_equal_to = test2( std::not_equal_to<>() ); | |
82 | auto greater = test2( std::greater<>() ); | |
83 | auto less = test2( std::less<>() ); | |
84 | auto greater_equal = test2( std::greater_equal<>() ); | |
85 | auto less_equal = test2( std::less_equal<>() ); | |
86 | ||
87 | auto logical_and = test2( std::logical_and<>() ); | |
88 | auto logical_or = test2( std::logical_or<>() ); | |
89 | auto logical_not = test1( std::logical_not<>() ); | |
90 | ||
91 | auto bit_and = test2( std::bit_and<>() ); | |
92 | auto bit_or = test2( std::bit_or<>() ); | |
93 | auto bit_xor = test2( std::bit_xor<>() ); | |
94 | auto bit_not = test1( std::bit_not<>() ); |