[libcxx-commits] [libcxx] [libc++][pstl] Implementation of parallel std::uninitialized_(copy|move)(_n) based on parallel __for_each (PR #223229)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 16 08:51:21 PDT 2026


================
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++17
+
+// UNSUPPORTED: libcpp-has-no-incomplete-pstl
+
+// <memory>
+
+// template <class ExecutionPolicy,
+//           class InputIterator,
+//           class ForwardIterator>
+//   ForwardIterator uninitialized_copy(ExecutionPolicy&& exec,
+//                                      InputIterator first, InputIterator last,
+//                                      ForwardIterator result);
+
+#include <atomic>
+#include <algorithm>
+#include <cassert>
+#include <cstring>
+#include <functional>
+#include <iterator>
+#include <memory>
+#include <numeric>
+
+#include "test_execution_policies.h"
+#include "test_iterators.h"
+#include "test_macros.h"
+#include "type_algorithms.h"
+#include "runway_sample.h"
+
+EXECUTION_POLICY_SFINAE_TEST(uninitialized_copy);
+
+static_assert(sfinae_test_uninitialized_copy<int, int*, int*, int*>);
+static_assert(!sfinae_test_uninitialized_copy<std::execution::parallel_policy, int*, int*, int*>);
+
+// Source type
+struct Src {
+  Src(int v) : value_(v) {}
+  Src(const Src&)            = delete;
+  Src& operator=(const Src&) = delete;
+  int value() const { return value_; }
+
+private:
+  int value_;
+};
+
+// Destination type
+struct Dst {
+  Dst(const Src& x) : value_(x.value()) {} // Can only be constructed from Src
+  Dst(const Dst&) = delete;
+  ~Dst() { value_ = 0; };
+  Dst& operator=(const Dst&) = delete;
+  int value() const { return value_; }
+
+private:
+  int value_;
+};
+
+template <class Iter1, class Iter2>
+struct TestCustomTypes {
+  template <class ExecutionPolicy>
+  void operator()(ExecutionPolicy&& policy) {
+    constexpr size_t n = 1073;
+    std::allocator<Src> alloc_src;
+    std::allocator<Dst> alloc_dst;
+    Src* source = alloc_src.allocate(n);
----------------
ldionne wrote:

I think the source could be a simple `std::array` or `std::vector` (here array since known at compile-time).

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


More information about the libcxx-commits mailing list