//===----------------------------------------------------------------------===// // // 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. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17 // template // constexpr int rotl(T x, unsigned int s) noexcept; // Remarks: This function shall not participate in overload resolution unless // T is an unsigned integer type #include #include #include #include #include "test_macros.h" class A{}; enum E1 : unsigned char { rEd }; enum class E2 : unsigned char { red }; template constexpr bool constexpr_test() { const T max = std::numeric_limits::max(); return std::rotl(T(1), 0) == T( 1) && std::rotl(T(1), 1) == T( 2) && std::rotl(T(1), 2) == T( 4) && std::rotl(T(1), 3) == T( 8) && std::rotl(T(1), 4) == T( 16) && std::rotl(T(1), 5) == T( 32) && std::rotl(T(1), 6) == T( 64) && std::rotl(T(1), 7) == T(128) && std::rotl(max, 0) == max && std::rotl(max, 1) == max && std::rotl(max, 2) == max && std::rotl(max, 3) == max && std::rotl(max, 4) == max && std::rotl(max, 5) == max && std::rotl(max, 6) == max && std::rotl(max, 7) == max ; } template void runtime_test() { ASSERT_SAME_TYPE(T, decltype(std::rotl(T(0), 0))); ASSERT_NOEXCEPT( std::rotl(T(0), 0)); const T val = std::numeric_limits::max() - 1; assert( std::rotl(val, 0) == val); assert( std::rotl(val, 1) == T((val << 1) + 1)); assert( std::rotl(val, 2) == T((val << 2) + 3)); assert( std::rotl(val, 3) == T((val << 3) + 7)); assert( std::rotl(val, 4) == T((val << 4) + 15)); assert( std::rotl(val, 5) == T((val << 5) + 31)); assert( std::rotl(val, 6) == T((val << 6) + 63)); assert( std::rotl(val, 7) == T((val << 7) + 127)); } int main(int, char**) { { auto lambda = [](auto x) -> decltype(std::rotl(x, 1U)) {}; using L = decltype(lambda); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert( std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); #ifndef _LIBCPP_HAS_NO_INT128 static_assert( std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); #endif static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); static_assert(!std::is_invocable_v, ""); } static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); static_assert(constexpr_test(), ""); #ifndef _LIBCPP_HAS_NO_INT128 static_assert(constexpr_test<__uint128_t>(), ""); #endif runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); runtime_test(); #ifndef _LIBCPP_HAS_NO_INT128 runtime_test<__uint128_t>(); { __uint128_t val = 168; // 0xA8 (aka 10101000) assert( std::rotl(val, 128) == 168); val <<= 32; assert( std::rotl(val, 96) == 168); val <<= 2; assert( std::rotl(val, 95) == 336); val <<= 3; assert( std::rotl(val, 90) == 84); assert( std::rotl(val, 218) == 84); } #endif return 0; }