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

Unified Diff: base/bind.h

Issue 2042223002: Introduce OnceClosure and BindOnce (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update docs Created 4 years, 4 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 | base/bind_internal.h » ('j') | base/callback.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind.h
diff --git a/base/bind.h b/base/bind.h
index 9cf65b67764b0cbcb393cd392f6fdb480d57496b..5d3b6cba11b7422e0e4f40d8c9313c3b21347f06 100644
--- a/base/bind.h
+++ b/base/bind.h
@@ -23,21 +23,46 @@
// terms and concepts.
namespace base {
+namespace internal {
+// Bind as RepeatingCallback.
template <typename Functor, typename... Args>
-inline base::Callback<MakeUnboundRunType<Functor, Args...>> Bind(
- Functor&& functor,
- Args&&... args) {
+inline RepeatingCallback<MakeUnboundRunType<Functor, Args...>>
+BindRepeating(Functor&& functor, Args&&... args) {
using BindState = internal::MakeBindStateType<Functor, Args...>;
using UnboundRunType = MakeUnboundRunType<Functor, Args...>;
using Invoker = internal::Invoker<BindState, UnboundRunType>;
- using CallbackType = Callback<UnboundRunType>;
+ using CallbackType = RepeatingCallback<UnboundRunType>;
return CallbackType(new BindState(std::forward<Functor>(functor),
std::forward<Args>(args)...),
&Invoker::Run);
}
+// Bind as OneShotCallback.
+template <typename Functor, typename... Args>
+inline OneShotCallback<MakeUnboundRunType<Functor, Args...>>
+BindOneShot(Functor&& functor, Args&&... args) {
+ using BindState = internal::MakeBindStateType<Functor, Args...>;
+ using UnboundRunType = MakeUnboundRunType<Functor, Args...>;
+ using Invoker = internal::Invoker<BindState, UnboundRunType>;
+
+ using CallbackType = OneShotCallback<UnboundRunType>;
+ return CallbackType(new BindState(std::forward<Functor>(functor),
+ std::forward<Args>(args)...),
+ &Invoker::RunOneShot);
+}
+
+} // namespace internal
+
+// Unannotated Bind.
Yuta Kitamura 2016/08/16 07:44:12 You probably want to mention that this version is
tzik 2016/08/16 15:18:59 Done.
+template <typename Functor, typename... Args>
+inline Callback<MakeUnboundRunType<Functor, Args...>>
+Bind(Functor&& functor, Args&&... args) {
+ return internal::BindRepeating(std::forward<Functor>(functor),
+ std::forward<Args>(args)...);
+}
+
} // namespace base
#endif // BASE_BIND_H_
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | base/callback.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698