99 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// <utility>12 13// constexpr bool cmp_greater(T t, U u) noexcept; // C++2014 15#include <utility>16#include <limits>17#include <numeric>18#include <tuple>19#include <cassert>20#include <type_traits>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_greater1() {38 constexpr Tuple<T> tup;39 assert(!std::cmp_greater(T(0), T(1)));40 assert(!std::cmp_greater(T(1), T(2)));41 assert(!std::cmp_greater(tup.min, tup.max));42 assert(!std::cmp_greater(tup.min, tup.mid));43 assert(!std::cmp_greater(tup.mid, tup.max));44 assert(std::cmp_greater(T(1), T(0)));45 assert(std::cmp_greater(T(10), T(5)));46 assert(std::cmp_greater(tup.max, tup.min));47 assert(std::cmp_greater(tup.mid, tup.min));48 assert(!std::cmp_greater(tup.mid, tup.mid));49 assert(!std::cmp_greater(tup.min, tup.min));50 assert(!std::cmp_greater(tup.max, tup.max));51 assert(std::cmp_greater(tup.max, 1));52 assert(std::cmp_greater(1, tup.min));53 assert(!std::cmp_greater(T(-1), T(-1)));54 assert(std::cmp_greater(-2, tup.min) == std::is_signed_v<T>);55 assert(!std::cmp_greater(tup.min, -2) == std::is_signed_v<T>);56 assert(!std::cmp_greater(-2, tup.max));57 assert(std::cmp_greater(tup.max, -2));58}59 60template <typename T, typename U>61constexpr void test_cmp_greater2() {62 assert(!std::cmp_greater(T(0), U(1)));63 assert(std::cmp_greater(T(1), U(0)));64}65 66template <class... Ts>67constexpr void test1(const std::tuple<Ts...>&) {68 (test_cmp_greater1<Ts>() , ...);69}70 71template <class T, class... Us>72constexpr void test2_impl(const std::tuple<Us...>&) {73 (test_cmp_greater2<T, Us>() , ...);74}75 76template <class... Ts, class UTuple>77constexpr void test2(const std::tuple<Ts...>&, const UTuple& utuple) {78 (test2_impl<Ts>(utuple) , ...);79}80 81constexpr bool test() {82 std::tuple<83#ifndef TEST_HAS_NO_INT12884 __int128_t, __uint128_t,85#endif86 unsigned long long, long long, unsigned long, long, unsigned int, int,87 unsigned short, short, unsigned char, signed char> types;88 test1(types);89 test2(types, types);90 return true;91}92 93int main(int, char**) {94 ASSERT_NOEXCEPT(std::cmp_greater(1, 0));95 test();96 static_assert(test());97 return 0;98}99