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

Issue 2109063006: Add stream logging support for base::Optional (Closed)

Created:
4 years, 5 months ago by Bryan McQuade
Modified:
4 years, 5 months ago
CC:
chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add stream logging support for base::Optional Other base types, such as base::TimeDelta, provide operator<< for use when logging, for example: LOG(ERROR) << "Some log message: " << time_delta; As we migrate some uses of base::TimeDelta to base::Optional<base::TimeDelta>, I'm finding that logged base::TimeDelta instances won't compile without this change. BUG=625132

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+11 lines, -0 lines) Patch
M base/optional.h View 2 chunks +11 lines, -0 lines 0 comments Download

Messages

Total messages: 13 (2 generated)
Bryan McQuade
PTAL
4 years, 5 months ago (2016-07-01 12:24:24 UTC) #2
mlamouri (slow - plz ping)
+danakj@ who reviewed the initial base/optional.h change.
4 years, 5 months ago (2016-07-01 12:35:02 UTC) #4
dcheng
std::optional doesn't appear to be streamable, which will present a problem if/when we migrate to ...
4 years, 5 months ago (2016-07-01 12:58:29 UTC) #5
Bryan McQuade
On 2016/07/01 at 12:58:29, dcheng wrote: > std::optional doesn't appear to be streamable, which will ...
4 years, 5 months ago (2016-07-01 13:00:42 UTC) #6
mlamouri (slow - plz ping)
On 2016/07/01 at 12:58:29, dcheng wrote: > std::optional doesn't appear to be streamable, which will ...
4 years, 5 months ago (2016-07-01 13:01:09 UTC) #7
mlamouri (slow - plz ping)
... though, maybe that shouldn't be in base/optional.h but base/logging.h? We seem to have at ...
4 years, 5 months ago (2016-07-01 13:03:05 UTC) #8
Bryan McQuade
+1 to adding this to base/logging.h, and then updating to std::optional when we migrate to ...
4 years, 5 months ago (2016-07-01 13:05:20 UTC) #9
Bryan McQuade
On 2016/07/01 at 13:05:20, Bryan McQuade wrote: > +1 to adding this to base/logging.h, and ...
4 years, 5 months ago (2016-07-01 19:06:39 UTC) #10
danakj
On Fri, Jul 1, 2016 at 12:06 PM, <bmcquade@chromium.org> wrote: > On 2016/07/01 at 13:05:20, ...
4 years, 5 months ago (2016-07-01 20:16:06 UTC) #11
Bryan McQuade
On 2016/07/01 at 20:16:06, danakj wrote: > On Fri, Jul 1, 2016 at 12:06 PM, ...
4 years, 5 months ago (2016-07-01 20:58:37 UTC) #12
dcheng
4 years, 5 months ago (2016-07-02 00:26:51 UTC) #13
Message was sent while issue was closed.
On 2016/07/01 20:58:37, Bryan McQuade wrote:
> On 2016/07/01 at 20:16:06, danakj wrote:
> > On Fri, Jul 1, 2016 at 12:06 PM, <mailto:bmcquade@chromium.org> wrote:
> > 
> > > On 2016/07/01 at 13:05:20, Bryan McQuade wrote:
> > > > +1 to adding this to base/logging.h, and then updating to std::optional
> > > > when we migrate to it. Daniel, Dana, how does that sound to you?
> > > >
> > > > On Fri, Jul 1, 2016 at 9:03 AM <mailto:mlamouri@chromium.org&gt; wrote:
> > > >
> > > > > ... though, maybe that shouldn't be in base/optional.h but
> > > base/logging.h?
> > > > > We
> > > > > seem to have at least one operator<< defined there for a std type.
> > > > >
> > > > > https://codereview.chromium.org/2109063006/
> > > > >
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google
Groups
> > > "Chromium-reviews" group.
> > > > To unsubscribe from this group and stop receiving emails from it, send
an
> > > email to mailto:chromium-reviews+unsubscribe@chromium.org.
> > > >
> > >
> > > Turns out we do make extensive use of operator<< for Optional<TimeDelta>,
> > > but
> > > only in a single .cc file. So for now I think I can drop the
> > > implementation for
> > > this into an anonymous namespace in that cc file. Happy to pursue this
> > > change
> > > further if we think it's generally useful, but I can also abandon it if
> > > preferred.
> > >
> > 
> > That sounds fine for now.
> > 
> > We do want the API to match the std one so we can swap it out when c++14
> > arrives in our toolchains. While we could put it in logging.h, I really
> > don't want to add more lines of code to that file if I can help it. And
> > logging the .value() is probably good enough normally too?
> > 
> > 
> > >
> > > https://codereview.chromium.org/2109063006/
> > >
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups
> "Chromium-reviews" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> email to mailto:chromium-reviews+unsubscribe@chromium.org.
> > 
> 
> Sounds good, will close this out.

Just to followup, we can't (easily) add operator<< for std::optional without
triggering undefined behavior.

From http://en.cppreference.com/w/cpp/language/extending_std:
"It is allowed to add template specializations for any standard library template
to the namespace std only if the declaration depends on a user-defined type and
the specialization satisfies all requirements for the original template, except
where such specializations are prohibited."

Powered by Google App Engine
This is Rietveld 408576698