[libcxx-commits] [libcxx] [libc++] <experimental/simd> Add swap functions of simd reference (PR #86478)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 4 22:06:53 PDT 2024


================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <experimental/simd>
+//
+// [simd.reference]
+// friend void swap(reference&& a, reference&& b) noexcept;
+// friend void swap(value_type& a, reference&& b) noexcept;
+// friend void swap(reference&& a, value_type& b) noexcept;
+
+#include "../test_utils.h"
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+template <class T, std::size_t>
+struct CheckSimdRefSwap {
+  template <class SimdAbi>
+  void operator()() {
+    ex::simd<T, SimdAbi> origin_simd_1(1);
+    ex::simd<T, SimdAbi> origin_simd_2(2);
+    T value = 3;
+
+    static_assert(noexcept(swap(origin_simd_1[0], origin_simd_2[0])));
----------------
joy2myself wrote:

@philnik777 
Is the current code what you want? Now the `swap` function can be called directly in the `std::experimental` namespace. But we now make the reference class a friend with all template instantiations of the `swap` function, which is different from being friends with specific `swap` functions for the corresponding parameter types. I think it is not what it is in specification.

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


More information about the libcxx-commits mailing list