diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-30 09:09:34 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-30 09:09:34 +0000 |
commit | cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef (patch) | |
tree | 48ce1068ad3c94af442bdb9b373329ff3300ef5f /base/bind.h.pump | |
parent | f3f0da43dfff66771f894b48c45c8c567062244f (diff) | |
download | chromium_src-cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef.zip chromium_src-cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef.tar.gz chromium_src-cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef.tar.bz2 |
Allow Bind() to take a Callback<> and bind all its free parameters.
Basically, turns base::Callback<void(...)> to base::Closure.
It turns out there are a number of use caess where an API takes a callback, and then wants to invoke the Callback on another thread. This piece of syntactic sugar removes the need for custom helper functions.
This isn't quite full currying, however it is much simpler to implement.
BUG=87287
TEST=none
Review URL: http://codereview.chromium.org/8073012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103446 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind.h.pump')
-rw-r--r-- | base/bind.h.pump | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/base/bind.h.pump b/base/bind.h.pump index 62b313f..eca00cd 100644 --- a/base/bind.h.pump +++ b/base/bind.h.pump @@ -63,6 +63,26 @@ $for BOUND_ARG , [[P$(BOUND_ARG)]]>( } ]] +]] $$ for BOUND + +// Specializations to allow binding all the free arguments in a +// pre-existing base::Callback<>. This does not give full support for +// currying, but is significantly simpler and addresses the use case +// where a base::Callback<> needs to be invoked on another context/thread. +$for BOUND [[ +$range BOUND_ARG 1..BOUND +$if BOUND != 0 [[ + +template <typename Sig, $for BOUND_ARG , [[typename P$(BOUND_ARG)]]> +base::Closure Bind(const base::Callback<Sig>& callback, [[]] +$for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]]) { + return base::Bind([[]] +&internal::BindMoreFunc$(BOUND)<Sig, $for BOUND_ARG , [[P$(BOUND_ARG)]]>, [[]] +callback, [[]] +$for BOUND_ARG , [[p$(BOUND_ARG)]]); +} + +]] ]] $$ for BOUND |