]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/function_objects/comparisons_void.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function_objects / comparisons_void.cc
CommitLineData
52066eae 1// { dg-do compile { target c++14 } }
d081231a 2
8d9254fc 3// Copyright (C) 2013-2020 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
24struct R { };
25
26struct 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
52L l;
53R r;
54
55// test unary function objects
56template<typename F, typename Check = typename F::is_transparent>
57bool
58test1(F f)
59{
60 f(l);
61 return true;
62}
63
64// test binary function objects
65template<typename F, typename Check = typename F::is_transparent>
66bool
67test2(F f)
68{
69 f(l, r);
70 return true;
71}
72
73auto plus = test2( std::plus<>() );
74auto minus = test2( std::minus<>() );
75auto multiplies = test2( std::multiplies<>() );
76auto divides = test2( std::divides<>() );
77auto modulus = test2( std::modulus<>() );
78auto negate = test1( std::negate<>() );
79
80auto equal_to = test2( std::equal_to<>() );
81auto not_equal_to = test2( std::not_equal_to<>() );
82auto greater = test2( std::greater<>() );
83auto less = test2( std::less<>() );
84auto greater_equal = test2( std::greater_equal<>() );
85auto less_equal = test2( std::less_equal<>() );
86
87auto logical_and = test2( std::logical_and<>() );
88auto logical_or = test2( std::logical_or<>() );
89auto logical_not = test1( std::logical_not<>() );
90
91auto bit_and = test2( std::bit_and<>() );
92auto bit_or = test2( std::bit_or<>() );
93auto bit_xor = test2( std::bit_xor<>() );
94auto bit_not = test1( std::bit_not<>() );