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