1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// <utility>
12
13// template<class T, class U>
14// constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20
15
16#include <utility>
17#include <limits>
18#include <numeric>
19#include <tuple>
20#include <cassert>
21
22#include "test_macros.h"
23
24template <typename T>
25struct Tuple {
26 T min;
27 T max;
28 T mid;
29 constexpr Tuple() {
30 min = std::numeric_limits<T>::min();
31 max = std::numeric_limits<T>::max();
32 mid = std::midpoint(min, max);
33 }
34};
35
36template <typename T>
37constexpr void test_cmp_not_equal1() {
38 constexpr Tuple<T> tup;
39 assert(!std::cmp_not_equal(T(0), T(0)));
40 assert(!std::cmp_not_equal(T(10), T(10)));
41 assert(!std::cmp_not_equal(tup.min, tup.min));
42 assert(!std::cmp_not_equal(tup.max, tup.max));
43 assert(std::cmp_not_equal(T(0), T(1)));
44 assert(std::cmp_not_equal(T(1), T(0)));
45 assert(std::cmp_not_equal(T(5), T(10)));
46 assert(std::cmp_not_equal(T(10), T(5)));
47 assert(std::cmp_not_equal(tup.min, tup.max));
48 assert(std::cmp_not_equal(tup.max, tup.min));
49 assert(std::cmp_not_equal(1, tup.max));
50 assert(std::cmp_not_equal(tup.max, 1));
51 assert(std::cmp_not_equal(1, tup.min));
52 assert(std::cmp_not_equal(tup.min, 1));
53 assert(std::cmp_not_equal(-2, tup.min));
54 assert(std::cmp_not_equal(tup.min, -2));
55 assert(std::cmp_not_equal(-2, tup.max));
56 assert(std::cmp_not_equal(tup.max, -2));
57}
58
59template <typename T, typename U>
60constexpr void test_cmp_not_equal2() {
61 constexpr Tuple<T> ttup;
62 constexpr Tuple<U> utup;
63 assert(!std::cmp_not_equal(T(0), U(0)));
64 assert(!std::cmp_not_equal(T(10), U(10)));
65 assert(std::cmp_not_equal(T(0), U(1)));
66 assert(std::cmp_not_equal(T(1), U(0)));
67 assert(std::cmp_not_equal(T(5), U(10)));
68 assert(std::cmp_not_equal(T(10), U(5)));
69 assert(std::cmp_not_equal(ttup.min, utup.max));
70 assert(std::cmp_not_equal(utup.min, ttup.max));
71}
72
73template <class... Ts>
74constexpr void test1(const std::tuple<Ts...>&) {
75 (test_cmp_not_equal1<Ts>() , ...);
76}
77
78template <class T, class... Us>
79constexpr void test2_impl(const std::tuple<Us...>&) {
80 (test_cmp_not_equal2<T, Us>() , ...);
81}
82
83template <class... Ts, class UTuple>
84constexpr void test2(const std::tuple<Ts...>&, const UTuple& utuple) {
85 (test2_impl<Ts>(utuple) , ...);
86}
87
88constexpr bool test() {
89 std::tuple<
90#ifndef TEST_HAS_NO_INT128
91 __int128_t, __uint128_t,
92#endif
93 unsigned long long, long long, unsigned long, long, unsigned int, int,
94 unsigned short, short, unsigned char, signed char> types;
95 test1(types);
96 test2(types, utuple: types);
97 return true;
98}
99
100int main(int, char**) {
101 ASSERT_NOEXCEPT(std::cmp_not_equal(0, 0));
102 test();
103 static_assert(test());
104 return 0;
105}
106

source code of libcxx/test/std/utilities/utility/utility.intcmp/intcmp.cmp_not_equal/cmp_not_equal.pass.cpp