| 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 |
|
| 23 |
template <typename T> |
| 24 |
struct 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 |
|
| 35 |
template <typename T> |
| 36 |
constexpr 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 |
|
| 59 |
template <typename T, typename U> |
| 60 |
constexpr 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 |
|
| 67 |
template <class... Ts> |
| 68 |
constexpr void test1(const std::tuple<Ts...>&) { |
| 69 |
(test_cmp_greater_equal1<Ts>() , ...); |
| 70 |
} |
| 71 |
|
| 72 |
template <class T, class... Us> |
| 73 |
constexpr void test2_impl(const std::tuple<Us...>&) { |
| 74 |
(test_cmp_greater_equal2<T, Us>() , ...); |
| 75 |
} |
| 76 |
|
| 77 |
template <class... Ts, class UTuple> |
| 78 |
constexpr void test2(const std::tuple<Ts...>&, const UTuple& utuple) { |
| 79 |
(test2_impl<Ts>(utuple) , ...); |
| 80 |
} |
| 81 |
|
| 82 |
constexpr 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, types); |
| 91 |
return true; |
| 92 |
} |
| 93 |
|
| 94 |
int main(int, char**) { |
| 95 |
ASSERT_NOEXCEPT(std::cmp_greater_equal(1, 0)); |
| 96 |
test(); |
| 97 |
static_assert(test()); |
| 98 |
return 0; |
| 99 |
} |