]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/function_objects/comparisons_void.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function_objects / comparisons_void.cc
CommitLineData
d081231a
JW
1// { dg-options " -std=gnu++1y " }
2// { dg-do compile }
3
aa118a03 4// Copyright (C) 2013-2014 Free Software Foundation, Inc.
d081231a
JW
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// 20.3.3 Comparisons
22
23#include <functional>
24
25struct R { };
26
27struct L
28{
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 R&) const { return *this; }
34 L operator-() const { return *this; }
35
36 bool operator==(const R&) const { return true; }
37 bool operator!=(const R&) const { return false; }
38 bool operator<(const R&) const { return false; }
39 bool operator<=(const R&) const { return true; }
40 bool operator>(const R&) const { return false; }
41 bool operator>=(const R&) const { return true; }
42
43 bool operator&&(const R&) const { return true; }
44 bool operator||(const R&) const { return true; }
45 bool operator!() const { return false; }
46
47 int operator&(const R&) const { return 1; }
48 int operator|(const R&) const { return 1; }
49 int operator^(const R&) const { return 0; }
50 int operator~() const { return 0; }
51};
52
53L l;
54R r;
55
56// test unary function objects
57template<typename F, typename Check = typename F::is_transparent>
58bool
59test1(F f)
60{
61 f(l);
62 return true;
63}
64
65// test binary function objects
66template<typename F, typename Check = typename F::is_transparent>
67bool
68test2(F f)
69{
70 f(l, r);
71 return true;
72}
73
74auto plus = test2( std::plus<>() );
75auto minus = test2( std::minus<>() );
76auto multiplies = test2( std::multiplies<>() );
77auto divides = test2( std::divides<>() );
78auto modulus = test2( std::modulus<>() );
79auto negate = test1( std::negate<>() );
80
81auto equal_to = test2( std::equal_to<>() );
82auto not_equal_to = test2( std::not_equal_to<>() );
83auto greater = test2( std::greater<>() );
84auto less = test2( std::less<>() );
85auto greater_equal = test2( std::greater_equal<>() );
86auto less_equal = test2( std::less_equal<>() );
87
88auto logical_and = test2( std::logical_and<>() );
89auto logical_or = test2( std::logical_or<>() );
90auto logical_not = test1( std::logical_not<>() );
91
92auto bit_and = test2( std::bit_and<>() );
93auto bit_or = test2( std::bit_or<>() );
94auto bit_xor = test2( std::bit_xor<>() );
95auto bit_not = test1( std::bit_not<>() );