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

via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 24 00:25:47 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:

I think I still don’t quite understand. I think `swap` should be the `friend` function inside the `simd_reference` class. It should be called only by instances of the `simd_reference` class with specific template parameters, rather than using it directly in the `std::experimental` namespace.

If I define the `template swap` function outside the `simd_reference` class, the `friend swap declaration` within the `simd_reference` class needs to include the entire template function, not just the `swap` function corresponding to the same template parameters of the specific instance of the `simd_reference` class. This seems inconsistent with the requirements of the specification.

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


More information about the libcxx-commits mailing list