[llvm-branch-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jun 6 20:45:29 PDT 2024


================
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MOVE_ONLY_FUNCTION_COMMON_H
+#define MOVE_ONLY_FUNCTION_COMMON_H
+
+#include <initializer_list>
+#include <type_traits>
+
+inline bool called;
+inline void call_func() noexcept { called = true; }
+
+struct MoveCounter {
+  int* counter_;
+  MoveCounter(int* counter) : counter_(counter) {}
+  MoveCounter(MoveCounter&& other) : counter_(other.counter_) { ++*counter_; }
+};
+
+struct TriviallyDestructible {
+  TriviallyDestructible() = default;
+  TriviallyDestructible(MoveCounter) {}
+  TriviallyDestructible(std::initializer_list<int>, MoveCounter) {}
+  void operator()() const noexcept { called = true; }
+  int operator()(int i) const noexcept { return i; }
+};
+
+struct TriviallyDestructibleTooLarge {
+  TriviallyDestructibleTooLarge() = default;
+  TriviallyDestructibleTooLarge(MoveCounter) {}
+  TriviallyDestructibleTooLarge(std::initializer_list<int>, MoveCounter) {}
+  void operator()() const noexcept { called = true; }
+  int operator()(int i) const noexcept { return i; }
+  char a[5 * sizeof(void*)];
+};
+
+struct NonTrivial {
+  NonTrivial() = default;
+  NonTrivial(MoveCounter) {}
+  NonTrivial(std::initializer_list<int>&, MoveCounter) {}
+  NonTrivial(NonTrivial&&) noexcept(false) {}
+  ~NonTrivial() {}
+
+  void operator()() const noexcept { called = true; }
+  int operator()(int i) const noexcept { return i; }
+};
+
+inline int get_val(int i) noexcept { return i; }
+
+enum class CallType {
+  None,
+  LValue,
+  RValue,
+  ConstLValue,
+  ConstRValue,
+};
+
+struct CallTypeChecker {
+  CallType* type;
+  using enum CallType;
----------------
EricWF wrote:

Nice types.

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


More information about the llvm-branch-commits mailing list