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

Let EventBaseLocal::getOrCreateFn take the callable by value

Summary:
[Folly] Let EventBaseLocal::getOrCreateFn take the callable by value, rather than by non-const lvalue ref.

This lets temporaries, including lambda expression temporaries, be passed as the callable argument.

Reviewed By: andriigrynenko

Differential Revision: D12831069

fbshipit-source-id: 4c61f2cd3fb3eeaab6e7c72d2b0458b657c9d107
parent a81ce979
......@@ -102,7 +102,7 @@ class EventBaseLocal : public detail::EventBaseLocalBase {
}
template <typename Func>
T& getOrCreateFn(EventBase& evb, Func& fn) {
T& getOrCreateFn(EventBase& evb, Func fn) {
// If this looks like it's copy/pasted from above, that's because it is.
// gcc has a bug (fixed in 4.9) that doesn't allow capturing variadic
// params in a lambda.
......
......@@ -69,8 +69,7 @@ TEST(EventBaseLocalTest, getOrCreate) {
folly::EventBase evb2;
EXPECT_EQ(ints.getOrCreate(evb2, 5), 5);
ints.erase(evb2);
auto creator = []() { return new int(4); };
EXPECT_EQ(ints.getOrCreateFn(evb2, creator), 4);
EXPECT_EQ(4, ints.getOrCreateFn(evb2, []() { return new int(4); }));
}
using IntPtr = std::unique_ptr<int>;
......
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