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
13 // template<class R, class T>
14 // constexpr bool in_range(T t) noexcept; // C++20
23 #include "test_macros.h"
31 min
= std::numeric_limits
<T
>::min();
32 max
= std::numeric_limits
<T
>::max();
33 mid
= std::midpoint(min
, max
);
38 constexpr void test_in_range1() {
39 constexpr Tuple
<T
> tup
;
40 assert(std::in_range
<T
>(tup
.min
));
41 assert(std::in_range
<T
>(tup
.min
+ 1));
42 assert(std::in_range
<T
>(tup
.max
));
43 assert(std::in_range
<T
>(tup
.max
- 1));
44 assert(std::in_range
<T
>(tup
.mid
));
45 assert(std::in_range
<T
>(tup
.mid
- 1));
46 assert(std::in_range
<T
>(tup
.mid
+ 1));
49 constexpr void test_in_range() {
50 constexpr Tuple
<std::uint8_t> utup8
;
51 constexpr Tuple
<std::int8_t> stup8
;
52 assert(!std::in_range
<std::int8_t>(utup8
.max
));
53 assert(std::in_range
<short>(utup8
.max
));
54 assert(!std::in_range
<std::uint8_t>(stup8
.min
));
55 assert(std::in_range
<std::int8_t>(utup8
.mid
));
56 assert(!std::in_range
<std::uint8_t>(stup8
.mid
));
57 assert(!std::in_range
<std::uint8_t>(-1));
60 template <class... Ts
>
61 constexpr void test1(const std::tuple
<Ts
...>&) {
62 (test_in_range1
<Ts
>() , ...);
65 constexpr bool test() {
67 #ifndef TEST_HAS_NO_INT128
68 __int128_t
, __uint128_t
,
70 unsigned long long, long long, unsigned long, long, unsigned int, int,
71 unsigned short, short, unsigned char, signed char> types
;
77 int main(int, char**) {
78 ASSERT_NOEXCEPT(std::in_range
<int>(-1));
80 static_assert(test());