[Openmp-commits] [clang-tools-extra] [lldb] [compiler-rt] [mlir] [libcxx] [openmp] [llvm] [libcxxabi] [lld] [clang] [libc] [libunwind] [polly] [flang] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

Mark de Wever via Openmp-commits openmp-commits at lists.llvm.org
Thu Jan 18 09:32:04 PST 2024


================
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <numeric>
+
+// template<class T>
+// constexpr T add_sat(T x, T y) noexcept;                     // freestanding
+
+#include <concepts>
+#include <numeric>
+
+template <typename T, typename U>
+concept CanDo = requires(T x, U y) {
+  { std::add_sat(x, y) } -> std::same_as<T>;
+};
+
+template <typename T, typename U>
+constexpr void test_constraint_success() {
+  static_assert(CanDo<T, T>);
+  static_assert(!CanDo<U, T>);
+  static_assert(!CanDo<T, U>);
+}
+
+template <typename T>
+constexpr void test_constraint_fail() {
+  using I = int;
+  static_assert(!CanDo<T, T>);
+  static_assert(!CanDo<I, T>);
+  static_assert(!CanDo<T, I>);
+}
+
+constexpr void test() {
+  // Contraint success - Signed
+  using SI = long long int;
+  test_constraint_success<signed char, SI>();
+  test_constraint_success<short int, SI>();
+  test_constraint_success<signed char, SI>();
+  test_constraint_success<short int, SI>();
+  test_constraint_success<int, SI>();
+  test_constraint_success<long int, SI>();
+  test_constraint_success<long long int, int>();
+#ifndef _LIBCPP_HAS_NO_INT128
----------------
mordante wrote:

```suggestion
#ifndef TEST_HAS_NO_INT128
```
In general we do not use libc++ internal macros. Our test suite is used by MSVC STL too to test their implementation. The `TEST_x` macros work for them. the `_LIBCPP_x` not. The exception is that you can use
`_LIBCPP_VERSION` if you want to test the library under test is libc++.

https://github.com/llvm/llvm-project/pull/77967


More information about the Openmp-commits mailing list