add folly::Function::asSharedProxy v2016.10.24.00
authorSven Over <over@fb.com>
Mon, 24 Oct 2016 05:06:45 +0000 (22:06 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Mon, 24 Oct 2016 05:08:57 +0000 (22:08 -0700)
commit62001f5ebab94e79faac4773023ff8381eff0ff1
tree0c324d831dbb1eff52b44f790cc5a4b69b5b3ed6
parentd458b0a14486b9d80d5644c7b4de60640c891df1
add folly::Function::asSharedProxy

Summary:
This diff adds a method to folly::Function that moves the
Function object into a copyable, callable proxy object.

folly::Function already has the asStdFunction method, which
does the same, but wraps the proxy object in a std::function.
When a copyable shared-state proxy of a folly::Function is needed,
it is not necessarily to turn it into a std::function.
If instead the shared proxy will be passed to several functions
taking folly::Function, what happens is the folly::Function
is moved on the heap, a shared_ptr is put into a std::function,
and that is wrapped in a new folly::Function, which always
requires a memory allocation, because std::function is not
noexcept-movable. When using asSharedProxy instead, an
unspecified copyable type is returned that can implicitly
converted into a folly::Function, but without an additional
memory allocation at this point.

Reviewed By: yfeldblum

Differential Revision: D4048621

fbshipit-source-id: b642027b0a6957058fe0089cceeb657ec52e8669
folly/Function.h
folly/test/FunctionTest.cpp