Commit 964cde07 authored by Uladzislau Paulovich's avatar Uladzislau Paulovich Committed by Facebook Github Bot

folly | Add explicit bool conversion operator to Function::SharedProxy

Summary: `folly::Function` has this explicit bool conversion operator and it makes sense to also have it for `SharedProxy`.

Reviewed By: yfeldblum, ericniebler

Differential Revision: D18504667

fbshipit-source-id: 32fede326c7a3eebd340dea9d118714a0cdfa5c0
parent 12049572
......@@ -337,6 +337,10 @@ class FunctionTraitsSharedProxy {
return (*sp_)(static_cast<A&&>(args)...);
}
explicit operator bool() const noexcept {
return sp_ != nullptr;
}
friend bool operator==(
FunctionTraitsSharedProxy<F, R, A...> const& proxy,
std::nullptr_t) noexcept {
......
......@@ -1103,6 +1103,20 @@ TEST(Function, asSharedProxy_empty) {
EXPECT_THROW(sp(3, 4), std::bad_function_call);
}
TEST(Function, asSharedProxy_explicit_bool_conversion) {
folly::Function<void(void)> f = []() {};
auto sp = std::move(f).asSharedProxy();
auto spcopy = sp;
EXPECT_TRUE(sp);
EXPECT_TRUE(spcopy);
folly::Function<void(void)> emptyF;
auto emptySp = std::move(emptyF).asSharedProxy();
auto emptySpcopy = emptySp;
EXPECT_FALSE(emptySp);
EXPECT_FALSE(emptySpcopy);
}
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