brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 5a07835 Raw
100 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// template<class T, class U>14//   constexpr bool cmp_less(T t, U u) noexcept;          // C++2015 16#include <utility>17#include <limits>18#include <numeric>19#include <tuple>20#include <cassert>21#include <type_traits>22 23#include "test_macros.h"24 25template <typename T>26struct Tuple {27  T min;28  T max;29  T mid;30  constexpr Tuple() {31    min = std::numeric_limits<T>::min();32    max = std::numeric_limits<T>::max();33    mid = std::midpoint(min, max);34  }35};36 37template <typename T>38constexpr void test_cmp_less1() {39  constexpr Tuple<T> tup;40  assert(std::cmp_less(T(0), T(1)));41  assert(std::cmp_less(T(1), T(2)));42  assert(std::cmp_less(tup.min, tup.max));43  assert(std::cmp_less(tup.min, tup.mid));44  assert(std::cmp_less(tup.mid, tup.max));45  assert(!std::cmp_less(T(1), T(0)));46  assert(!std::cmp_less(T(10), T(5)));47  assert(!std::cmp_less(tup.max, tup.min));48  assert(!std::cmp_less(tup.mid, tup.min));49  assert(!std::cmp_less(tup.mid, tup.mid));50  assert(!std::cmp_less(tup.min, tup.min));51  assert(!std::cmp_less(tup.max, tup.max));52  assert(!std::cmp_less(tup.max, 1));53  assert(!std::cmp_less(1, tup.min));54  assert(!std::cmp_less(T(-1), T(-1)));55  assert(!std::cmp_less(-2, tup.min) == std::is_signed_v<T>);56  assert(std::cmp_less(tup.min, -2) == std::is_signed_v<T>);57  assert(std::cmp_less(-2, tup.max));58  assert(!std::cmp_less(tup.max, -2));59}60 61template <typename T, typename U>62constexpr void test_cmp_less2() {63  assert(std::cmp_less(T(0), U(1)));64  assert(!std::cmp_less(T(1), U(0)));65}66 67template <class... Ts>68constexpr void test1(const std::tuple<Ts...>&) {69  (test_cmp_less1<Ts>() , ...);70}71 72template <class T, class... Us>73constexpr void test2_impl(const std::tuple<Us...>&) {74  (test_cmp_less2<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_INT12885      __int128_t, __uint128_t,86#endif87      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 94int main(int, char**) {95  ASSERT_NOEXCEPT(std::cmp_less(0, 1));96  test();97  static_assert(test());98  return 0;99}100