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// constexpr bool cmp_greater(T t, U u) noexcept; // C++20
14
15#include <utility>
16#include <limits>
17#include <numeric>
18#include <tuple>
19#include <cassert>
20
21#include "test_macros.h"
22
23template <typename T>
24struct Tuple {
25 T min;
26 T max;
27 T mid;
28 constexpr Tuple() {
29 min = std::numeric_limits<T>::min();
30 max = std::numeric_limits<T>::max();
31 mid = std::midpoint(min, max);
32 }
33};
34
35template <typename T>
36constexpr void test_cmp_greater1() {
37 constexpr Tuple<T> tup;
38 assert(!std::cmp_greater(T(0), T(1)));
39 assert(!std::cmp_greater(T(1), T(2)));
40 assert(!std::cmp_greater(tup.min, tup.max));
41 assert(!std::cmp_greater(tup.min, tup.mid));
42 assert(!std::cmp_greater(tup.mid, tup.max));
43 assert(std::cmp_greater(T(1), T(0)));
44 assert(std::cmp_greater(T(10), T(5)));
45 assert(std::cmp_greater(tup.max, tup.min));
46 assert(std::cmp_greater(tup.mid, tup.min));
47 assert(!std::cmp_greater(tup.mid, tup.mid));
48 assert(!std::cmp_greater(tup.min, tup.min));
49 assert(!std::cmp_greater(tup.max, tup.max));
50 assert(std::cmp_greater(tup.max, 1));
51 assert(std::cmp_greater(1, tup.min));
52 assert(!std::cmp_greater(T(-1), T(-1)));
53 assert(std::cmp_greater(-2, tup.min) == std::is_signed_v<T>);
54 assert(!std::cmp_greater(tup.min, -2) == std::is_signed_v<T>);
55 assert(!std::cmp_greater(-2, tup.max));
56 assert(std::cmp_greater(tup.max, -2));
57}
58
59template <typename T, typename U>
60constexpr void test_cmp_greater2() {
61 assert(!std::cmp_greater(T(0), U(1)));
62 assert(std::cmp_greater(T(1), U(0)));
63}
64
65template <class... Ts>
66constexpr void test1(const std::tuple<Ts...>&) {
67 (test_cmp_greater1<Ts>() , ...);
68}
69
70template <class T, class... Us>
71constexpr void test2_impl(const std::tuple<Us...>&) {
72 (test_cmp_greater2<T, Us>() , ...);
73}
74
75template <class... Ts, class UTuple>
76constexpr void test2(const std::tuple<Ts...>&, const UTuple& utuple) {
77 (test2_impl<Ts>(utuple) , ...);
78}
79
80constexpr bool test() {
81 std::tuple<
82#ifndef TEST_HAS_NO_INT128
83 __int128_t, __uint128_t,
84#endif
85 unsigned long long, long long, unsigned long, long, unsigned int, int,
86 unsigned short, short, unsigned char, signed char> types;
87 test1(types);
88 test2(types, utuple: types);
89 return true;
90}
91
92int main(int, char**) {
93 ASSERT_NOEXCEPT(std::cmp_greater(1, 0));
94 test();
95 static_assert(test());
96 return 0;
97}
98

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