1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // template <class _Tp>
13 // _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept
19 #include "test_macros.h"
24 constexpr void constexpr_test()
26 constexpr T array
[1000] = {};
27 ASSERT_SAME_TYPE(decltype(std::midpoint(array
, array
)), const T
*);
28 ASSERT_NOEXCEPT( std::midpoint(array
, array
));
30 static_assert(std::midpoint(array
, array
) == array
, "");
31 static_assert(std::midpoint(array
, array
+ 1000) == array
+ 500, "");
33 static_assert(std::midpoint(array
, array
+ 9) == array
+ 4, "");
34 static_assert(std::midpoint(array
, array
+ 10) == array
+ 5, "");
35 static_assert(std::midpoint(array
, array
+ 11) == array
+ 5, "");
36 static_assert(std::midpoint(array
+ 9, array
) == array
+ 5, "");
37 static_assert(std::midpoint(array
+ 10, array
) == array
+ 5, "");
38 static_assert(std::midpoint(array
+ 11, array
) == array
+ 6, "");
44 T array
[1000] = {}; // we need an array to make valid pointers
45 ASSERT_SAME_TYPE(decltype(std::midpoint(array
, array
)), T
*);
46 ASSERT_NOEXCEPT( std::midpoint(array
, array
));
48 assert(std::midpoint(array
, array
) == array
);
49 assert(std::midpoint(array
, array
+ 1000) == array
+ 500);
51 assert(std::midpoint(array
, array
+ 9) == array
+ 4);
52 assert(std::midpoint(array
, array
+ 10) == array
+ 5);
53 assert(std::midpoint(array
, array
+ 11) == array
+ 5);
54 assert(std::midpoint(array
+ 9, array
) == array
+ 5);
55 assert(std::midpoint(array
+ 10, array
) == array
+ 5);
56 assert(std::midpoint(array
+ 11, array
) == array
+ 6);
58 // explicit instantiation
59 ASSERT_SAME_TYPE(decltype(std::midpoint
<T
>(array
, array
)), T
*);
60 ASSERT_NOEXCEPT(std::midpoint
<T
>(array
, array
));
61 assert(std::midpoint
<T
>(array
, array
) == array
);
62 assert(std::midpoint
<T
>(array
, array
+ 1000) == array
+ 500);
69 runtime_test
<const T
>();
70 runtime_test
< volatile T
>();
71 runtime_test
<const volatile T
>();
73 // The constexpr tests are always const, but we can test them anyway.
75 constexpr_test
<const T
>();
77 // GCC 9.0.1 (unreleased as of 2019-03) barfs on this, but we have a bot for it.
78 // Uncomment when gcc 9.1 is released
79 #ifndef TEST_COMPILER_GCC
80 constexpr_test
< volatile T
>();
81 constexpr_test
<const volatile T
>();
90 pointer_test
<double>();