//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // 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 // ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd5215 /wd5216 // // template // constexpr T* midpoint(T* a, T* b); // // Constraints: // - T is an object type. // // Mandates: // - T is a complete type. #include #include #include #include #include #include "test_macros.h" using FuncPtr = void (*)(); struct Incomplete; template concept has_midpoint = requires(T a, T b) { std::midpoint(a, b); }; static_assert(!has_midpoint); static_assert(!has_midpoint); LIBCPP_STATIC_ASSERT(!has_midpoint); static_assert(!has_midpoint); static_assert(!has_midpoint); static_assert(!has_midpoint); static_assert(!has_midpoint); template 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 constexpr bool test_pointer() { ASSERT_SAME_TYPE(decltype(std::midpoint(std::declval(), std::declval())), T*); ASSERT_NOEXCEPT(std::midpoint(std::declval(), std::declval())); std::remove_cv_t array[20] = {}; assert(check(array, 0, 0, 0)); assert(check(array, 1, 1, 1)); assert(check(array, 0, 9, 4)); assert(check(array, 0, 10, 5)); assert(check(array, 0, 11, 5)); assert(check(array, 9, 0, 5)); assert(check(array, 10, 0, 5)); assert(check(array, 11, 0, 6)); assert(check(array, 0, 18, 9)); assert(check(array, 2, 12, 7)); return true; } template void test() { assert(test_pointer()); assert(test_pointer()); assert(test_pointer()); assert(test_pointer()); static_assert(test_pointer()); static_assert(test_pointer()); } int main(int, char**) { test(); test(); test(); return 0; }