]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/function_objects/range.cmp/greater.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function_objects / range.cmp / greater.cc
CommitLineData
8d9254fc 1// Copyright (C) 2019-2020 Free Software Foundation, Inc.
da8ddcec
JW
2//
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)
7// any later version.
8
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.
13
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/>.
17
18// { dg-options "-std=gnu++2a" }
19// { dg-do run { target c++2a } }
20
21#include <functional>
22#include <testsuite_hooks.h>
23
24// C++20 [range.cmp]
25
26using F = std::ranges::greater;
27static_assert( std::is_default_constructible_v<F> );
28static_assert( std::is_copy_constructible_v<F> );
29static_assert( std::is_move_constructible_v<F> );
30static_assert( std::is_copy_assignable_v<F> );
31static_assert( std::is_move_assignable_v<F> );
32
33static_assert( ! std::is_invocable_v<F> );
34static_assert( ! std::is_invocable_v<F, int&> );
35static_assert( ! std::is_invocable_v<F, int, void> );
36static_assert( ! std::is_invocable_v<F, int, void*> );
37static_assert( std::is_nothrow_invocable_r_v<bool, F&, int&, int> );
38static_assert( std::is_nothrow_invocable_r_v<bool, F, const long&, char> );
39static_assert( std::is_nothrow_invocable_r_v<bool, const F&, short, int&> );
40static_assert( std::is_nothrow_invocable_r_v<bool, const F, const char, char> );
41
42using T = F::is_transparent; // required typedef
43
44static_assert( ! std::ranges::greater{}(99, 99.0) );
45static_assert( std::ranges::greater{}(99.01, 99) );
46static_assert( std::ranges::greater{}(990, 140L) );
47
48void
49test01()
50{
51 F f;
52 int a[2]{};
53 VERIFY( ! f(&a, (void*)&a[0]) );
54 VERIFY( f((void*)&a[1], &a) );
55 VERIFY( f(&a + 1, (void*)(a + 1)) );
56 VERIFY( ! f(&a, (void*)(a + 1)) );
57}
58
59struct X { };
60int operator==(X, X) { return 2; }
61int operator!=(X, X) { return 0; }
62int operator<(X, X) noexcept { return 0; }
63int operator>(X, X) { return 0; }
64int operator<=(X, X) { return 3; }
65int operator>=(X, X) { return 4; }
66
67static_assert( std::is_nothrow_invocable_r_v<bool, F&, X, X> );
68
69void
70test02()
71{
72 X x;
73 F f;
74 VERIFY( ! f(x, x) );
75}
76
77int
78main()
79{
80 test01();
81 test02();
82}