Commit 80bef0fa authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Make Function shared proxy empty when empty

Summary: [Folly] Make `Function` shared proxy empty when constructed with an empty `Function`, just like it would be when constructed with `nullptr`.

Reviewed By: ericniebler, vitaut

Differential Revision: D18518858

fbshipit-source-id: fdad5b4cd30a1fda5465dae80054c5c74837faa9
parent 38256f47
......@@ -328,7 +328,8 @@ class FunctionTraitsSharedProxy {
public:
explicit FunctionTraitsSharedProxy(std::nullptr_t) noexcept {}
explicit FunctionTraitsSharedProxy(Function<F>&& func)
: sp_(std::make_shared<Function<F>>(std::move(func))) {}
: sp_(func ? std::make_shared<Function<F>>(std::move(func))
: std::shared_ptr<Function<F>>()) {}
R operator()(A&&... args) const {
if (!sp_) {
throw_exception<std::bad_function_call>();
......
......@@ -1097,6 +1097,12 @@ TEST(Function, asSharedProxy_nullptr) {
EXPECT_THROW(sp(3, 4), std::bad_function_call);
}
TEST(Function, asSharedProxy_empty) {
auto func = folly::Function<int(int, int) const>();
auto sp = std::move(func).asSharedProxy();
EXPECT_THROW(sp(3, 4), std::bad_function_call);
}
TEST(Function, NoAllocatedMemoryAfterMove) {
Functor<int, 100> foo;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment