[PATCH] D48349: [ADT] Add llvm::unique_function which is like std::function but supporting move-only closures.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 2 15:57:10 PDT 2018


chandlerc added inline comments.


================
Comment at: llvm/include/llvm/ADT/FunctionExtras.h:161
+public:
+  unique_function() = default;
+  unique_function(std::nullptr_t /*null_callable*/) {}
----------------
timshen wrote:
> The default ctor doesn't initialize CallbackAndInlineFlag to a valid empty state, does it? We probably want to zero-initialize it.
> 
> `std::function`'s default ctor is not trivial either.
Yep, the underlying value is set to zero by an in-class initializer.

This isn't about making something trivial, its just the simplest implementation.


================
Comment at: llvm/include/llvm/ADT/FunctionExtras.h:181
+  unique_function(unique_function &&RHS) noexcept {
+    // Copy the callback and inline flag.
+    CallbackAndInlineFlag = RHS.CallbackAndInlineFlag;
----------------
timshen wrote:
> `if (!(bool)RHS) { ... }`
Not 100% sure what you're going for here, but yes I should bail out early when RHS is null. Let me know if you intended something else.


Repository:
  rL LLVM

https://reviews.llvm.org/D48349





More information about the llvm-commits mailing list