[libcxx-commits] [libcxx] [libc++][numeric] Refactor `std::midpoint` tests (PR #175531)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 12 04:45:02 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: eiytoq (eiytoq)
<details>
<summary>Changes</summary>
Extracted NFC changes from PR #<!-- -->175388.
---
Patch is 22.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/175531.diff
3 Files Affected:
- (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp (+134-104)
- (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.integer.pass.cpp (+94-120)
- (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp (+40-66)
``````````diff
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
index 0d28cff511dee..1332d714eb8b6 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
@@ -5,131 +5,161 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// REQUIRES: std-at-least-c++20
// <numeric>
-// template <class _Float>
-// _Tp midpoint(_Float __a, _Float __b) noexcept
-//
+// template <class _Fp>
+// _Fp midpoint(_Fp __a, _Fp __b) noexcept
+#include <cassert>
+#include <cmath>
+#include <concepts>
#include <limits>
#include <numeric>
-#include <cassert>
#include "test_macros.h"
#include "fp_compare.h"
-// Totally arbitrary picks for precision
template <typename T>
-constexpr T fp_error_pct();
-
-template <>
-constexpr float fp_error_pct<float>() { return 1.0e-4f; }
-
-template <>
-constexpr double fp_error_pct<double>() { return 1.0e-12; }
+constexpr bool is_nan(T x) {
+ return x != x;
+}
-template <>
-constexpr long double fp_error_pct<long double>() { return 1.0e-13l; }
+template <typename T>
+constexpr T get_error_pct() {
+ if constexpr (std::same_as<T, float>)
+ return 1.0e-4f;
+ else if constexpr (std::same_as<T, double>)
+ return 1.0e-12;
+ else
+ return 1.0e-13l;
+}
+template <typename T>
+constexpr bool check_near(T a, T b, T expect) {
+ if (std::is_constant_evaluated())
+ return true;
+ return fptest_close_pct(std::midpoint(a, b), expect, get_error_pct<T>());
+}
template <typename T>
-void fp_test()
-{
- ASSERT_SAME_TYPE(T, decltype(std::midpoint(T(), T())));
- ASSERT_NOEXCEPT( std::midpoint(T(), T()));
-
- constexpr T maxV = std::numeric_limits<T>::max();
- constexpr T minV = std::numeric_limits<T>::min();
-
-// Things that can be compared exactly
- static_assert((std::midpoint(T(0), T(0)) == T(0)), "");
- static_assert((std::midpoint(T(2), T(4)) == T(3)), "");
- static_assert((std::midpoint(T(4), T(2)) == T(3)), "");
- static_assert((std::midpoint(T(3), T(4)) == T(3.5)), "");
- static_assert((std::midpoint(T(0), T(0.4)) == T(0.2)), "");
-
-// Things that can't be compared exactly
- constexpr T pct = fp_error_pct<T>();
- assert((fptest_close_pct(std::midpoint(T( 1.3), T(11.4)), T( 6.35), pct)));
- assert((fptest_close_pct(std::midpoint(T(11.33), T(31.45)), T(21.39), pct)));
- assert((fptest_close_pct(std::midpoint(T(-1.3), T(11.4)), T( 5.05), pct)));
- assert((fptest_close_pct(std::midpoint(T(11.4), T(-1.3)), T( 5.05), pct)));
- assert((fptest_close_pct(std::midpoint(T(0.1), T(0.4)), T(0.25), pct)));
-
- assert((fptest_close_pct(std::midpoint(T(11.2345), T(14.5432)), T(12.88885), pct)));
-
-// From e to pi
- assert((fptest_close_pct(std::midpoint(T(2.71828182845904523536028747135266249775724709369995),
- T(3.14159265358979323846264338327950288419716939937510)),
- T(2.92993724102441923691146542731608269097720824653752), pct)));
-
- assert((fptest_close_pct(std::midpoint(maxV, T(0)), maxV/2, pct)));
- assert((fptest_close_pct(std::midpoint(T(0), maxV), maxV/2, pct)));
- assert((fptest_close_pct(std::midpoint(minV, T(0)), minV/2, pct)));
- assert((fptest_close_pct(std::midpoint(T(0), minV), minV/2, pct)));
- assert((fptest_close_pct(std::midpoint(maxV, maxV), maxV, pct)));
- assert((fptest_close_pct(std::midpoint(minV, minV), minV, pct)));
- assert((fptest_close_pct(std::midpoint(maxV, minV), maxV/2, pct)));
- assert((fptest_close_pct(std::midpoint(minV, maxV), maxV/2, pct)));
-
-// Near the min and the max
- assert((fptest_close_pct(std::midpoint(maxV*T(0.75), maxV*T(0.50)), maxV*T(0.625), pct)));
- assert((fptest_close_pct(std::midpoint(maxV*T(0.50), maxV*T(0.75)), maxV*T(0.625), pct)));
- assert((fptest_close_pct(std::midpoint(minV*T(2), minV*T(8)), minV*T(5), pct)));
-
-// Big numbers of different signs
- assert((fptest_close_pct(std::midpoint(maxV*T( 0.75), maxV*T(-0.5)), maxV*T( 0.125), pct)));
- assert((fptest_close_pct(std::midpoint(maxV*T(-0.75), maxV*T( 0.5)), maxV*T(-0.125), pct)));
-
-// Denormalized values
-// TODO
-
-// Check two values "close to each other"
- T d1 = T(3.14);
- T d0 = std::nextafter(d1, T(2));
- T d2 = std::nextafter(d1, T(5));
- assert(d0 < d1); // sanity checking
- assert(d1 < d2); // sanity checking
+constexpr bool check_exact(T a, T b, T expect) {
+ T res = std::midpoint(a, b);
+ if (is_nan(expect)) {
+ return is_nan(res);
+ } else {
+ return res == expect;
+ }
+}
+
+template <std::floating_point T>
+constexpr bool test_ppc_edge_cases() {
+ if (std::is_constant_evaluated())
+ return true;
+// For 128 bit long double implemented as 2 doubles on PowerPC,
+// nextafterl() of libm gives imprecise results which fails the
+// midpoint() tests below. So skip the test for this case.
#if defined(__PPC__) && (defined(__LONG_DOUBLE_128__) && __LONG_DOUBLE_128__) && \
!(defined(__LONG_DOUBLE_IEEE128__) && __LONG_DOUBLE_IEEE128__)
-// For 128 bit long double implemented as 2 doubles on PowerPC,
-// nextafterl() of libm gives imprecise results which fails the
-// midpoint() tests below. So skip the test for this case.
- if constexpr (sizeof(T) != 16)
+ if constexpr (sizeof(T) == 16)
+ return true;
#endif
- {
- // Since there's nothing in between, the midpoint has to be one or the other
- T res;
- res = std::midpoint(d0, d1);
- assert(res == d0 || res == d1);
- assert(d0 <= res);
- assert(res <= d1);
- res = std::midpoint(d1, d0);
- assert(res == d0 || res == d1);
- assert(d0 <= res);
- assert(res <= d1);
-
- res = std::midpoint(d1, d2);
- assert(res == d1 || res == d2);
- assert(d1 <= res);
- assert(res <= d2);
- res = std::midpoint(d2, d1);
- assert(res == d1 || res == d2);
- assert(d1 <= res);
- assert(res <= d2);
- }
+
+ T d1 = 3.14;
+ T d0 = std::nextafter(d1, T{2});
+ T d2 = std::nextafter(d1, T{5});
+
+ auto verify = [](T res, T low, T high) { return (res == low || res == high) && (low <= res && res <= high); };
+
+ return verify(std::midpoint(d0, d1), d0, d1) && verify(std::midpoint(d1, d2), d1, d2);
}
+template <typename T>
+constexpr bool test_floating_points() {
+ ASSERT_SAME_TYPE(T, decltype(std::midpoint(T{}, T{})));
+ ASSERT_NOEXCEPT(std::midpoint(T{}, T{}));
+
+ constexpr T max_v = std::numeric_limits<T>::max();
+ constexpr T min_v = std::numeric_limits<T>::min();
+ constexpr T denorm_min = std::numeric_limits<T>::denorm_min();
+ constexpr T inf = std::numeric_limits<T>::infinity();
+ constexpr T qnan = std::numeric_limits<T>::quiet_NaN();
+
+ // Things that can be compared exactly
+ assert(check_exact<T>(0, 0, 0));
+ assert(check_exact<T>(2, 4, 3));
+ assert(check_exact<T>(4, 2, 3));
+ assert(check_exact<T>(3, 4, 3.5));
+ assert(check_exact<T>(0, 0.4, 0.2));
+ assert(check_exact<T>(-2, -4, -3));
+ assert(check_exact<T>(-2, 2, 0));
+ assert(check_exact<T>(2, -2, 0));
+
+ // Infinity
+ assert(check_exact<T>(inf, inf, inf));
+ assert(check_exact<T>(-inf, -inf, -inf));
+ if (!std::is_constant_evaluated()) {
+ assert(check_exact<T>(inf, -inf, qnan));
+ }
+ assert(check_exact<T>(inf, 0, inf));
+
+ // NaN
+ if (!std::is_constant_evaluated()) {
+ assert(check_exact<T>(qnan, 0, qnan));
+ assert(check_exact<T>(qnan, qnan, qnan));
+ }
+
+ // Subnormal
+ assert(check_exact<T>(denorm_min, 0, 0));
+ assert(check_exact<T>(denorm_min, denorm_min, denorm_min));
+
+ // Things that can't be compared exactly
+ assert(check_near<T>(1.3, 11.4, 6.35));
+ assert(check_near<T>(11.33, 31.45, 21.39));
+ assert(check_near<T>(-1.3, 11.4, 5.05));
+ assert(check_near<T>(11.4, -1.3, 5.05));
+ assert(check_near<T>(11.2345, 14.5432, 12.88885));
+ assert(check_near<T>(2.71828182845904523536028747135266249775724709369995,
+ 3.14159265358979323846264338327950288419716939937510,
+ 2.92993724102441923691146542731608269097720824653752));
+
+ assert(check_near<T>(max_v, 0, max_v / 2));
+ assert(check_near<T>(0, max_v, max_v / 2));
+ assert(check_near<T>(min_v, 0, min_v / 2));
+ assert(check_near<T>(0, min_v, min_v / 2));
+ assert(check_near<T>(max_v, max_v, max_v));
+ assert(check_near<T>(min_v, min_v, min_v));
+ assert(check_near<T>(max_v, min_v, max_v / 2));
+ assert(check_near<T>(min_v, max_v, max_v / 2));
+
+ // Near the min and the max
+ assert(check_near<T>(max_v * 0.75, max_v * 0.50, max_v * 0.625));
+ assert(check_near<T>(max_v * 0.50, max_v * 0.75, max_v * 0.625));
+ assert(check_near<T>(min_v * 2, min_v * 8, min_v * 5));
+
+ // Big numbers of different signs
+ assert(check_near<T>(max_v * 0.75, max_v * -0.50, max_v * 0.125));
+ assert(check_near<T>(max_v * -0.75, max_v * 0.50, max_v * -0.125));
+
+ assert(test_ppc_edge_cases<T>());
+
+ return true;
+}
+
+constexpr bool test() {
+ test_floating_points<float>();
+ test_floating_points<double>();
+ test_floating_points<long double>();
+
+ return true;
+}
-int main (int, char**)
-{
- fp_test<float>();
- fp_test<double>();
- fp_test<long double>();
+int main(int, char**) {
+ test();
+ static_assert(test());
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.integer.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.integer.pass.cpp
index c506d0776a02c..c5ad2792fb2e3 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.integer.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.integer.pass.cpp
@@ -5,140 +5,114 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// REQUIRES: std-at-least-c++20
+
// <numeric>
// template <class _Tp>
// _Tp midpoint(_Tp __a, _Tp __b) noexcept
-//
+// Constraints:
+// - T is an arithmetic type other than bool.
-#include <stdint.h>
-#include <limits>
-#include <numeric>
#include <cassert>
+#include <concepts>
#include <cstddef>
-#include <cstdint>
+#include <limits>
+#include <numeric>
+
#include "test_macros.h"
+#include "type_algorithms.h"
template <typename T>
-void signed_test()
-{
- constexpr T zero{0};
- constexpr T one{1};
- constexpr T two{2};
- constexpr T three{3};
- constexpr T four{4};
-
- ASSERT_SAME_TYPE(decltype(std::midpoint(T(), T())), T);
- ASSERT_NOEXCEPT( std::midpoint(T(), T()));
- using limits = std::numeric_limits<T>;
-
- static_assert(std::midpoint(one, three) == two, "");
- static_assert(std::midpoint(three, one) == two, "");
-
- assert(std::midpoint(zero, zero) == zero);
- assert(std::midpoint(zero, two) == one);
- assert(std::midpoint(two, zero) == one);
- assert(std::midpoint(two, two) == two);
-
- assert(std::midpoint(one, four) == two);
- assert(std::midpoint(four, one) == three);
- assert(std::midpoint(three, four) == three);
- assert(std::midpoint(four, three) == four);
-
- assert(std::midpoint(T( 3), T( 4)) == T(3));
- assert(std::midpoint(T( 4), T( 3)) == T(4));
- assert(std::midpoint(T(-3), T( 4)) == T(0));
- assert(std::midpoint(T(-4), T( 3)) == T(-1));
- assert(std::midpoint(T( 3), T(-4)) == T(0));
- assert(std::midpoint(T( 4), T(-3)) == T(1));
- assert(std::midpoint(T(-3), T(-4)) == T(-3));
- assert(std::midpoint(T(-4), T(-3)) == T(-4));
-
- static_assert(std::midpoint(limits::min(), limits::max()) == T(-1), "");
- static_assert(std::midpoint(limits::max(), limits::min()) == T( 0), "");
-
- static_assert(std::midpoint(limits::min(), T(6)) == limits::min()/2 + 3, "");
- assert( std::midpoint(T(6), limits::min()) == limits::min()/2 + 3);
- assert( std::midpoint(limits::max(), T(6)) == limits::max()/2 + 4);
- static_assert(std::midpoint(T(6), limits::max()) == limits::max()/2 + 3, "");
-
- assert( std::midpoint(limits::min(), T(-6)) == limits::min()/2 - 3);
- static_assert(std::midpoint(T(-6), limits::min()) == limits::min()/2 - 3, "");
- static_assert(std::midpoint(limits::max(), T(-6)) == limits::max()/2 - 2, "");
- assert( std::midpoint(T(-6), limits::max()) == limits::max()/2 - 3);
+constexpr void test_signed() {
+ ASSERT_SAME_TYPE(decltype(std::midpoint(T{}, T{})), T);
+ ASSERT_NOEXCEPT(std::midpoint(T{}, T{}));
+ using limits = std::numeric_limits<T>;
+
+ assert(std::midpoint(T{1}, T{3}) == T{2});
+ assert(std::midpoint(T{3}, T{1}) == T{2});
+
+ assert(std::midpoint(T{0}, T{0}) == T{0});
+ assert(std::midpoint(T{0}, T{2}) == T{1});
+ assert(std::midpoint(T{2}, T{0}) == T{1});
+ assert(std::midpoint(T{2}, T{2}) == T{2});
+
+ assert(std::midpoint(T{1}, T{4}) == T{2});
+ assert(std::midpoint(T{4}, T{1}) == T{3});
+ assert(std::midpoint(T{3}, T{4}) == T{3});
+ assert(std::midpoint(T{4}, T{3}) == T{4});
+
+ assert(std::midpoint(T{-3}, T{4}) == T{0});
+ assert(std::midpoint(T{-4}, T{3}) == T{-1});
+ assert(std::midpoint(T{3}, T{-4}) == T{0});
+ assert(std::midpoint(T{4}, T{-3}) == T{1});
+ assert(std::midpoint(T{-3}, T{-4}) == T{-3});
+ assert(std::midpoint(T{-4}, T{-3}) == T{-4});
+
+ assert(std::midpoint(limits::min(), limits::max()) == T{-1});
+ assert(std::midpoint(limits::max(), limits::min()) == T{0});
+
+ assert(std::midpoint(limits::min(), T{6}) == T{limits::min() / 2 + 3});
+ assert(std::midpoint(T{6}, limits::min()) == T{limits::min() / 2 + 3});
+
+ assert(std::midpoint(limits::max(), T{6}) == T{limits::max() / 2 + 4});
+ assert(std::midpoint(T{6}, limits::max()) == T{limits::max() / 2 + 3});
+
+ assert(std::midpoint(limits::min(), T{-6}) == T{limits::min() / 2 - 3});
+ assert(std::midpoint(T{-6}, limits::min()) == T{limits::min() / 2 - 3});
+
+ assert(std::midpoint(limits::max(), T{-6}) == T{limits::max() / 2 - 2});
+ assert(std::midpoint(T{-6}, limits::max()) == T{limits::max() / 2 - 3});
}
template <typename T>
-void unsigned_test()
-{
- constexpr T zero{0};
- constexpr T one{1};
- constexpr T two{2};
- constexpr T three{3};
- constexpr T four{4};
-
- ASSERT_SAME_TYPE(decltype(std::midpoint(T(), T())), T);
- ASSERT_NOEXCEPT( std::midpoint(T(), T()));
- using limits = std::numeric_limits<T>;
- const T half_way = (limits::max() - limits::min())/2;
-
- static_assert(std::midpoint(one, three) == two, "");
- static_assert(std::midpoint(three, one) == two, "");
-
- assert(std::midpoint(zero, zero) == zero);
- assert(std::midpoint(zero, two) == one);
- assert(std::midpoint(two, zero) == one);
- assert(std::midpoint(two, two) == two);
-
- assert(std::midpoint(one, four) == two);
- assert(std::midpoint(four, one) == three);
- assert(std::midpoint(three, four) == three);
- assert(std::midpoint(four, three) == four);
-
- assert(std::midpoint(limits::min(), limits::max()) == T(half_way));
- assert(std::midpoint(limits::max(), limits::min()) == T(half_way + 1));
-
- static_assert(std::midpoint(limits::min(), T(6)) == limits::min()/2 + 3, "");
- assert( std::midpoint(T(6), limits::min()) == limits::min()/2 + 3);
- assert( std::midpoint(limits::max(), T(6)) == half_way + 4);
- static_assert(std::midpoint(T(6), limits::max()) == half_way + 3, "");
+constexpr void test_unsigned() {
+ ASSERT_SAME_TYPE(decltype(std::midpoint(T{}, T{})), T);
+ ASSERT_NOEXCEPT(std::midpoint(T{}, T{}));
+
+ using limits = std::numeric_limits<T>;
+ const T half_way = (limits::max() - limits::min()) / 2;
+
+ assert(std::midpoint(T{1}, T{3}) == T{2});
+ assert(std::midpoint(T{3}, T{1}) == T{2});
+
+ assert(std::midpoint(T{0}, T{0}) == T{0});
+ assert(std::midpoint(T{0}, T{2}) == T{1});
+ assert(std::midpoint(T{2}, T{0}) == T{1});
+ assert(std::midpoint(T{2}, T{2}) == T{2});
+
+ assert(std::midpoint(T{1}, T{4}) == T{2});
+ assert(std::midpoint(T{4}, T{1}) == T{3});
+ assert(std::midpoint(T{3}, T{4}) == T{3});
+ assert(std::midpoint(T{4}, T{3}) == T{4});
+
+ assert(std::midpoint(limits::min(), limits::max()) == half_way);
+ assert(std::midpoint(limits::max(), limits::min()) == T{half_way + 1});
+
+ assert(std::midpoint(limits::min(), T{6}) == T{3});
+ assert(std::midpoint(T{6}, limits::min()) == T{3});
+
+ assert(std::midpoint(limits::max(), T{6}) == T{half_way + 4});
+ assert(std::midpoint(T{6}, limits::max()) == T{half_way + 3});
+}
+
+constexpr bool test() {
+ types::for_each(types::integer_types(), []<class T>() {
+ if constexpr (!std::same_as<T, bool>) {
+ if constexpr (std::signed_integral<T>) {
+ test_signed<T>();
+ } else {
+ test_unsigned<T>();
+ }
+ }
+ });
+ return true;
}
+int main(int, char**) {
+ test();
+ static_assert(test());
-int main(int, char**)
-{
- signed_test<signed char>();
- signed_test<short>();
- signed_test<int>();
- signed_test<long>();
- signed_test<long long>();
-
- signed_test<std::int8_t>();
- signed_test<std::int16_t>();
- signed_test<std::int32_t>();
- signed_test<std::int64_t>();
-
- unsigned_test<unsigned char>();
- unsigned_test<unsigned short>();
- unsigned_test<unsigned int>();
- unsigned_test<unsigned long>();
- unsigned_test<unsigned long long>();
-
- unsigned_test<std::uint8_t>();
- unsigned_test<std::uint16_t>();
- unsigned_test<std::uint32_t>();
- unsigned_test<std::uint64_t>();
-
-#ifndef TEST_HAS_NO_INT128
- unsigned_test<__uint128_t>();
- signed_test<__int128_t>();
-#endif
-
-// int_test<char>();
- signed_test<std::ptrdiff_t>();
- unsigned_test<std::size_t>();
-
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
index e8a25c174076a..a6639bd8529de 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
@@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// REQUIRES: std-at-least-c++20
// MSVC warning C5215: a function parameter with a volatile qualified type is deprecated in C++20
// MSVC warning C5216: a volatile qualified return type is deprecated in C++20
@@ -16,83 +16,57 @@
// template <class _Tp>
// _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept
-//
+// Constraints:
+// - T is a complete object type.
-#include <numeric>
#include <cassert>
+#include <cstddef>
+#include <numeric>
+#include <type_traits>
+#include <utility>
#include "test_macros.h"
-
-
template <typename T>
-constexpr void constexpr_test()
-{
- constexpr T array[1000] = {};
- ASSERT_SAME_TYPE(decltype(std::midpoint(array, array)), const T*);
- ASSERT_NOEXCEPT( std::midpoint(array, array));
-
- static_assert(std::midpoint(array, array) == array, "");
- static_assert(std::midpoint(array, array + 1000) == array + 500, "");
-
- static_assert(std::midpoint(array, array + 9) == array + 4, "");
- static_assert(std::midpoint(array, array + 10) == array + 5, "");
- static_assert(std::midpoint(array, array + 11) == array + 5, "");
- static_assert(std::midpoint(array + 9, array) == array + 5, "");
- static_assert(std::midpoint(array + 10, array) == array + 5, "");
- static_assert(std::midpoint(array + 11, array) == array + 6, "");
+constexpr bool check(T* base, std::ptrdiff_t i, std::ptrdiff_t j, std::ptrdiff_t expect) {
+ return std::midpoint(base + i, base + j) == base + expect;
}
template <typename T>
-void runtime_test()
-{
- T array[10...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/175531
More information about the libcxx-commits
mailing list