diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-20 00:36:17 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-20 00:36:17 +0000 |
commit | 6c59ab46825b33b24780dace2b403aadf429bc15 (patch) | |
tree | 247590feebb80fc389d82633da913993449b7a01 /base/callback_internal.h | |
parent | 0236aa8e8a64cc2ef7d6ebc9dc9e23ccd3dd469e (diff) | |
download | chromium_src-6c59ab46825b33b24780dace2b403aadf429bc15.zip chromium_src-6c59ab46825b33b24780dace2b403aadf429bc15.tar.gz chromium_src-6c59ab46825b33b24780dace2b403aadf429bc15.tar.bz2 |
Extend scoped_ptr to be closer to unique_ptr. Support custom deleters, and deleting arrays.
This is based on the modifications by "Geoffrey Romer"
<gromer@google.com> to Google's internal version of scoped_ptr<>. All cleaver tricks are his, not mine. :)
It brings most of the features of C++11's unique_ptr<> into this class and should eliminate the need for scoped_array<>, scoped_malloc_free<>, and possibly a few other scopers. Please refer to the unique_ptr<> API for documentation.
Divergence from unique_ptr<>:
1) DefaultDeleter<T[n]> (sized-arrays) is explicitly disabled because this construct would cause the single-object delete to be called on a pointer to a T[n]. It is impossible to construct a single-object new expression that returns a T[n]*. You can only get this with new[] which should correspond to DefaultDeleter<T[n][]>. This issue has been raised with the C++ LWG as it is possible a unique_ptr<> spec defect.
2) Reference types for Deleters are not supported. This simplifies implementation significantly because there is no need to distinguish between the converting constructor + converting assignment operator and their move constructor + move assignment operator.
4) Move-only Deleters are not supported. Avoids the need to emulate std::forward().
BUG=109874
TBR=dhollowa,kinuko,ananta,hans,scherkus
Review URL: https://codereview.chromium.org/11149006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback_internal.h')
-rw-r--r-- | base/callback_internal.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/base/callback_internal.h b/base/callback_internal.h index 2f834c3..d9aba39 100644 --- a/base/callback_internal.h +++ b/base/callback_internal.h @@ -130,10 +130,10 @@ struct CallbackParamTraits<T[]> { // TODO(ajwong): We might be able to use SFINAE to search for the existence of // a Pass() function in the type and avoid the whitelist in CallbackParamTraits // and CallbackForward. -template <typename T> -struct CallbackParamTraits<scoped_ptr<T> > { - typedef scoped_ptr<T> ForwardType; - typedef scoped_ptr<T> StorageType; +template <typename T, typename D> +struct CallbackParamTraits<scoped_ptr<T, D> > { + typedef scoped_ptr<T, D> ForwardType; + typedef scoped_ptr<T, D> StorageType; }; template <typename T> @@ -173,8 +173,8 @@ struct CallbackParamTraits<ScopedVector<T> > { template <typename T> T& CallbackForward(T& t) { return t; } -template <typename T> -scoped_ptr<T> CallbackForward(scoped_ptr<T>& p) { return p.Pass(); } +template <typename T, typename D> +scoped_ptr<T, D> CallbackForward(scoped_ptr<T, D>& p) { return p.Pass(); } template <typename T> scoped_array<T> CallbackForward(scoped_array<T>& p) { return p.Pass(); } |