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_equal(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_greater_equal1() {
37 constexpr Tuple<T> tup;
38 assert(!std::cmp_greater_equal(T(0), T(1)));
39 assert(!std::cmp_greater_equal(T(1), T(2)));
40 assert(!std::cmp_greater_equal(tup.min, tup.max));
41 assert(!std::cmp_greater_equal(tup.min, tup.mid));
42 assert(!std::cmp_greater_equal(tup.mid, tup.max));
43 assert(std::cmp_greater_equal(T(1), T(0)));
44 assert(std::cmp_greater_equal(T(10), T(5)));
45 assert(std::cmp_greater_equal(tup.max, tup.min));
46 assert(std::cmp_greater_equal(tup.mid, tup.min));
47 assert(std::cmp_greater_equal(tup.mid, tup.mid));
48 assert(std::cmp_greater_equal(tup.min, tup.min));
49 assert(std::cmp_greater_equal(tup.max, tup.max));
50 assert(std::cmp_greater_equal(tup.max, 1));
51 assert(std::cmp_greater_equal(1, tup.min));
52 assert(std::cmp_greater_equal(T(-1), T(-1)));
53 assert(std::cmp_greater_equal(-2, tup.min) == std::is_signed_v<T>);
54 assert(std::cmp_greater_equal(tup.min, -2) == std::is_unsigned_v<T>);
55 assert(!std::cmp_greater_equal(-2, tup.max));
56 assert(std::cmp_greater_equal(tup.max, -2));
57}
58
59template <typename T, typename U>
60constexpr void test_cmp_greater_equal2() {
61 assert(!std::cmp_greater_equal(T(0), U(1)));
62 assert(std::cmp_greater_equal(T(1), U(0)));
63 assert(std::cmp_greater_equal(T(0), U(0)));
64 assert(std::cmp_greater_equal(T(1), U(1)));
65}
66
67template <class... Ts>
68constexpr void test1(const std::tuple<Ts...>&) {
69 (test_cmp_greater_equal1<Ts>() , ...);
70}
71
72template <class T, class... Us>
73constexpr void test2_impl(const std::tuple<Us...>&) {
74 (test_cmp_greater_equal2<T, Us>() , ...);
75}
76
77template <class... Ts, class UTuple>
78constexpr void test2(const std::tuple<Ts...>&, const UTuple& utuple) {
79 (test2_impl<Ts>(utuple) , ...);
80}
81
82constexpr bool test() {
83 std::tuple<
84#ifndef TEST_HAS_NO_INT128
85 __int128_t, __uint128_t,
86#endif
87 unsigned long long, long long, unsigned long, long, unsigned int, int,
88 unsigned short, short, unsigned char, signed char> types;
89 test1(types);
90 test2(types, utuple: types);
91 return true;
92}
93
94int main(int, char**) {
95 ASSERT_NOEXCEPT(std::cmp_greater_equal(1, 0));
96 test();
97 static_assert(test());
98 return 0;
99}
100

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