Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(795)

Unified Diff: third_party/WebKit/Source/wtf/Functional.h

Issue 1975013003: Add support for std::unique_ptr as this pointer in WTF::bind() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use const&. Add tests. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/FunctionalTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/Functional.h
diff --git a/third_party/WebKit/Source/wtf/Functional.h b/third_party/WebKit/Source/wtf/Functional.h
index 1878058ca3129b6ea492b1fc958633ff409a2d0b..b0ff0cccd3b82f97ace0f236c00f41478a3781ee 100644
--- a/third_party/WebKit/Source/wtf/Functional.h
+++ b/third_party/WebKit/Source/wtf/Functional.h
@@ -60,12 +60,12 @@ namespace WTF {
// 1) Pass by rvalue reference.
//
// void yourFunction(Argument&& argument) { ... }
-// OwnPtr<Function<void(Argument&&)>> functor = bind<Argument&&>(yourFunction);
+// std::unique_ptr<Function<void(Argument&&)>> functor = bind<Argument&&>(yourFunction);
//
// 2) Pass by value.
//
// void yourFunction(Argument argument) { ... }
-// OwnPtr<Function<void(Argument)>> functor = bind<Argument>(yourFunction);
+// std::unique_ptr<Function<void(Argument)>> functor = bind<Argument>(yourFunction);
//
// Note that with the latter there will be *two* move constructions happening, because there needs to be at least one
// intermediary function call taking an argument of type "Argument" (i.e. passed by value). The former case does not
@@ -84,7 +84,7 @@ namespace WTF {
// }
//
// ...
-// OwnPtr<Function<void()>> functor = bind(yourFunction, passed(Argument()));
+// std::unique_ptr<Function<void()>> functor = bind(yourFunction, passed(Argument()));
// ...
// (*functor)();
//
@@ -166,6 +166,12 @@ public:
}
template <typename... IncomingParameters>
+ R operator()(const std::unique_ptr<C>& c, IncomingParameters&&... parameters)
+ {
+ return (c.get()->*m_function)(std::forward<IncomingParameters>(parameters)...);
+ }
+
+ template <typename... IncomingParameters>
R operator()(const WeakPtr<C>& c, IncomingParameters&&... parameters)
{
C* obj = c.get();
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/FunctionalTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698