-
-
Save EricWF/df7e02ca931075b62caac587b7c0cf27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===----------------------------------------------------------------------===// | |
// | |
// The LLVM Compiler Infrastructure | |
// | |
// This file is dual licensed under the MIT and the University of Illinois Open | |
// Source Licenses. See LICENSE.TXT for details. | |
// | |
//===----------------------------------------------------------------------===// | |
// <algorithm> | |
// template <typename _Tp> _Tp __half_as_unsigned(const _Tp&); | |
// __half_as_unsigned divide integer number by 2 as unsigned number | |
// if it's safe to do so. It can be an important optimization for lower bound, | |
// for example. | |
#include <algorithm> | |
#include <cassert> | |
#include <limits> | |
#include <type_traits> | |
#include "test_macros.h" | |
#include "user_defined_integral.hpp" | |
template <class IntType, class LimitType = IntType> | |
TEST_CONSTEXPR bool test(IntType max_v = std::numeric_limits<LimitType>::max()) { | |
return std::__half_positive(max_v) == max_v / 2; | |
} | |
int main() | |
{ | |
{ | |
assert(test<char>()); | |
assert(test<int>()); | |
assert(test<long>()); | |
assert(test<size_t>()); | |
assert((test<UserDefinedIntegral<int>, int>())); | |
#if !defined(_LIBCPP_HAS_NO_INT128) | |
assert(test<__int128_t>()); | |
#endif | |
} | |
#if TEST_STD_VER >= 11 | |
{ | |
static_assert(test<char>(), ""); | |
static_assert(test<int>(), ""); | |
static_assert(test<long>(), ""); | |
static_assert(test<size_t>(), ""); | |
#if !defined(_LIBCPP_HAS_NO_INT128) | |
static_assert(test<__int128_t>(), ""); | |
#endif | |
} | |
#endif // TEST_STD_VER >= 11 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment