//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 // // template // constexpr R saturate_cast(T x) noexcept; // freestanding #include #include #include "test_macros.h" template concept CanDo = requires(T x) { { std::saturate_cast(x) } -> std::same_as; }; template constexpr void test_constraint_success() { static_assert(CanDo); static_assert(CanDo); static_assert(CanDo); } template constexpr void test_constraint_fail() { using I = int; using R = T; static_assert(!CanDo); static_assert(!CanDo); static_assert(!CanDo); static_assert(!CanDo); } constexpr void test() { // Contraint success - Signed using SI = long long int; test_constraint_success(); test_constraint_success(); test_constraint_success(); test_constraint_success(); test_constraint_success(); test_constraint_success(); test_constraint_success(); #ifndef TEST_HAS_NO_INT128 test_constraint_success<__int128_t, SI>(); #endif // Contraint success - Unsigned using UI = unsigned long long int; test_constraint_success(); test_constraint_success(); test_constraint_success(); test_constraint_success(); test_constraint_success(); #ifndef TEST_HAS_NO_INT128 test_constraint_success(); #endif // Contraint failure test_constraint_fail(); test_constraint_fail(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS test_constraint_fail(); #endif test_constraint_fail(); test_constraint_fail(); test_constraint_fail(); test_constraint_fail(); test_constraint_fail(); test_constraint_fail(); }