1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // __half_positive divides an integer number by 2 as unsigned number for known types.
13 // It can be an important optimization for lower bound, for example.
18 #include <type_traits>
20 #include "test_macros.h"
21 #include "user_defined_integral.hpp"
25 template <class IntType, class UnderlyingType = IntType>
26 TEST_CONSTEXPR bool test(IntType max_v = IntType(std::numeric_limits<UnderlyingType>::max())) {
27 return std::__half_positive(max_v) == max_v / 2;
38 assert((test<UserDefinedIntegral<int>, int>()));
39 assert(test<size_t>());
40 #if !defined(_LIBCPP_HAS_NO_INT128)
41 assert(test<__int128_t>());
42 #endif // !defined(_LIBCPP_HAS_NO_INT128)
45 #if TEST_STD_VER >= 11
47 static_assert(test<char>(), "");
48 static_assert(test<int>(), "");
49 static_assert(test<long>(), "");
50 static_assert(test<size_t>(), "");
51 #if !defined(_LIBCPP_HAS_NO_INT128)
52 static_assert(test<__int128_t>(), "");
53 #endif // !defined(_LIBCPP_HAS_NO_INT128)
55 #endif // TEST_STD_VER >= 11