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

Side by Side Diff: base/callback_helpers.h

Issue 9717021: Make Callback::Reset() return a copy to support use-cases where Run() ends up modifying |*this|. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base::ResetAndReturn is born. Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This defines helpful methods for dealing with Callbacks. Because Callbacks
6 // are implemented using templates, with a class per callback signature, adding
7 // methods to Callback<> itself is unattractive (lots of extra code gets
8 // generated). Instead, consider adding methods here.
9 //
10 // ResetAndReturn(&cb) is like cb.Reset() but allows executing a callback (via a
11 // copy) after the original callback is Reset(). This can be handy if Run()
12 // reads/writes the variable holding the Callback.
13
14 #ifndef BASE_CALLBACK_HELPERS_H_
15 #define BASE_CALLBACK_HELPERS_H_
16
17 #include "base/callback.h"
18
19 namespace base {
20
21 template <typename Sig>
22 base::Callback<Sig> ResetAndReturn(base::Callback<Sig>* cb) {
23 base::Callback<Sig> ret(*cb);
24 cb->Reset();
25 return ret;
26 }
27
28 } // namespace base
29
30 #endif // BASE_CALLBACK_HELPERS_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/callback_unittest.cc » ('j') | base/callback_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698