|
|
Created:
8 years, 2 months ago by enne (OOO) Modified:
8 years, 2 months ago CC:
chromium-reviews, erikwright+watch_chromium.org, gavinp+memory_chromium.org, danakj, tfarina, awong, levin Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
DescriptionAllow scoped_ptr variables to be used in boolean expressions
BUG=none
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=160570
Patch Set 1 #
Total comments: 6
Patch Set 2 : Address review comments #Messages
Total messages: 13 (0 generated)
I find it tedious to have to .get() any scoped_ptr variable that I want to use in a conditional statement, e.g.: scoped_ptr<foo> x; if (x.get()) { /* stuff */ } With this patch, this is now legal: scoped_ptr<foo> x; if (x) { /* stuff */ } Reference: http://www.artima.com/cppsource/safebool.html
This is helpful for converting from OwnPtr to scoped_ptr in cc/, since OwnPtr seems to allow this test.
/me adds a reviewer who is actually an OWNER.
+jyasskin Jeffrey, will unique_ptr support this? If not, I'm not inclined to approve this, since our long-term plan is to switch to std::unique_ptr instead of scoped_ptr. On Fri, Oct 5, 2012 at 10:39 AM, <enne@chromium.org> wrote: > /me adds a reviewer who is actually an OWNER. > > https://codereview.chromium.**org/11028044/<https://codereview.chromium.org/1... >
On Fri, Oct 5, 2012 at 6:14 PM, William Chan (陈智昌) <willchan@chromium.org> wrote: > +jyasskin > > Jeffrey, will unique_ptr support this? If not, I'm not inclined to approve > this, since our long-term plan is to switch to std::unique_ptr instead of > scoped_ptr. > It seems so. http://en.cppreference.com/w/cpp/memory/unique_ptr -- Thiago
On Fri, Oct 5, 2012 at 2:14 PM, William Chan (陈智昌) <willchan@chromium.org> wrote: > +jyasskin > > Jeffrey, will unique_ptr support this? If not, I'm not inclined to approve > this, since our long-term plan is to switch to std::unique_ptr instead of > scoped_ptr. Yes, unique_ptr has an explicit operator bool: [unique.ptr.single.observers]. (And via Thiago's link: http://en.cppreference.com/w/cpp/memory/unique_ptr/operator_bool) > On Fri, Oct 5, 2012 at 10:39 AM, <enne@chromium.org> wrote: >> >> /me adds a reviewer who is actually an OWNER. >> >> https://codereview.chromium.org/11028044/ > >
I'm headed into the office and will sanity check the CL then. On Oct 5, 2012 2:26 PM, "Jeffrey Yasskin" <jyasskin@chromium.org> wrote: > On Fri, Oct 5, 2012 at 2:14 PM, William Chan (陈智昌) > <willchan@chromium.org> wrote: > > +jyasskin > > > > Jeffrey, will unique_ptr support this? If not, I'm not inclined to > approve > > this, since our long-term plan is to switch to std::unique_ptr instead of > > scoped_ptr. > > Yes, unique_ptr has an explicit operator bool: > [unique.ptr.single.observers]. (And via Thiago's link: > http://en.cppreference.com/w/cpp/memory/unique_ptr/operator_bool) > > > On Fri, Oct 5, 2012 at 10:39 AM, <enne@chromium.org> wrote: > >> > >> /me adds a reviewer who is actually an OWNER. > >> > >> https://codereview.chromium.org/11028044/ > > > > >
Just have a few nits. https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h#newc... base/memory/scoped_ptr.h:207: // implicitly convertable to a real bool (which is dangerous). s/convertable/convertible/ https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h#newc... base/memory/scoped_ptr.h:208: typedef C* scoped_ptr::*testable; Since testable is a type, please name it Testable. https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h#newc... base/memory/scoped_ptr.h:209: operator testable() const { return ptr_ ? &scoped_ptr::ptr_ : 0; } We use NULL, a la Google C++ Style Guide.
Jeffrey offers the great suggestion of conditionally compiling with explicit operator bool() in C++11 mode. You shouldn't do that here, but we should consider that in a future CL. I need to check on the status of our C++11 build. After you commit this, please announce your change in chromium-dev@, since people will probably be glad to avoid the .get() annoyance. Also, just to clarify my approval, I did it because we aren't losing much by further separating from backwards compatibility with google3 scoped_ptr, since they are switching to unique_ptr anyway, which we are moving toward too.
Thanks, I'll send an email to chromium-dev once this lands. If only C++11x constructs worked everywhere...</wistful> https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h#newc... base/memory/scoped_ptr.h:207: // implicitly convertable to a real bool (which is dangerous). On 2012/10/05 22:19:13, willchan wrote: > s/convertable/convertible/ Done. *blush* https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h#newc... base/memory/scoped_ptr.h:208: typedef C* scoped_ptr::*testable; On 2012/10/05 22:19:13, willchan wrote: > Since testable is a type, please name it Testable. Done. https://codereview.chromium.org/11028044/diff/1/base/memory/scoped_ptr.h#newc... base/memory/scoped_ptr.h:209: operator testable() const { return ptr_ ? &scoped_ptr::ptr_ : 0; } On 2012/10/05 22:19:13, willchan wrote: > We use NULL, a la Google C++ Style Guide. Done.
lgtm
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/enne@chromium.org/11028044/11001
Change committed as 160570 |