[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
Fri Jun 29 18:51:58 PDT 2018


chandlerc marked an inline comment as done.
chandlerc added a comment.

Thanks so much for the careful review Tim!



================
Comment at: llvm/include/llvm/ADT/function.h:236
+
+  ReturnT operator()(ParamTs... Params) {
+    void *CallableAddr =
----------------
timshen wrote:
> I think I understand the perfect-forwarding problem better now. Suppose we have the following user code:
>     unique_function<void(string)> f(...);
>     string a;
>     f(a);
> 
> Is the string copy-constructed once or twice? I figured that it'd be twice, (1) when calling `operator()`, (2) when calling `CallImpl()`.
> 
> Regardless of the solution, can we add a test case for that?
Ah, there is an interesting case here. I've added tests that much more carefully cover all the variations of both functionality and the number of moves and copies triggered.

There is a fair amount of logic that goes into getting this right however, so please do look through the updated code.


Repository:
  rL LLVM

https://reviews.llvm.org/D48349





More information about the llvm-commits mailing list