[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
Wed Jun 20 01:13:59 PDT 2018


chandlerc created this revision.
chandlerc added reviewers: rsmith, dblaikie, zturner, timshen.
Herald added subscribers: mgorny, mcrosier, sanjoy.

Most of the core optimizations for std::function are here plus
a potentially novel one that detects trivially movable and destroyable
functors and implements those with fewer indirections.

This is especially useful as we start trying to add concurrency
primitives as those often end up with move-only types (futures,
promises, etc) and wanting them to work through lambdas.

As further work, we could add better support for things like const-qualified
operator()s to support more algorithms, and r-value ref qualified operator()s
to model call-once. None of that is here though.

We can also provide our own llvm::function that has some of the optimizations
used in this class, but with copy semantics instead of move semantics.

This is motivated by increasing usage of things like executors and the task
queue where it is useful to embed move-only types like a std::promise within
a type erased function. That isn't possible without this version of a type
erased function.


Repository:
  rL LLVM

https://reviews.llvm.org/D48349

Files:
  llvm/include/llvm/ADT/function.h
  llvm/include/llvm/Support/Compiler.h
  llvm/include/llvm/Support/PointerLikeTypeTraits.h
  llvm/unittests/ADT/CMakeLists.txt
  llvm/unittests/ADT/FunctionTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48349.152031.patch
Type: text/x-patch
Size: 15448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180620/a0149dc6/attachment.bin>


More information about the llvm-commits mailing list