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

Issue 1413763003: Introduce rtc::Maybe<T>, which either contains a T or not. (Closed)

Created:
5 years, 2 months ago by kwiberg-webrtc
Modified:
5 years, 2 months ago
CC:
webrtc-reviews_webrtc.org, tterriberry_mozilla.com
Base URL:
https://chromium.googlesource.com/external/webrtc.git@master
Target Ref:
refs/pending/heads/master
Project:
webrtc
Visibility:
Public.

Description

Introduce rtc::Maybe<T>, which either contains a T or not. It's a simple std::experimental::optional-wannabe. For simplicity and portability, it still secretly contains a (default-constructed) T when it's supposedly empty. This restriction is fine for simple types. One important application is for the return type of functions. For example, a function which either returns a size_t or fails can return rtc::Maybe<size_t>. BUG=webrtc:5028 R=andrew@webrtc.org, mgraczyk@chromium.org Committed: https://crrev.com/6e587200db7ddae0d33e5187b73acdd41175584c Cr-Commit-Position: refs/heads/master@{#10353}

Patch Set 1 #

Patch Set 2 : MSVC lacks support for C++11 =default for move construction and assignment #

Total comments: 2

Patch Set 3 : Make constructors explicit #

Total comments: 31

Patch Set 4 : Bug fix moved-from documentation #

Patch Set 5 : Add value_or method #

Patch Set 6 : Try to make clang/gcc and MSVC do things in the same order #

Patch Set 7 : Try again #

Patch Set 8 : Make constructors implicit again #

Unified diffs Side-by-side diffs Delta from patch set Stats (+609 lines, -0 lines) Patch
M webrtc/base/BUILD.gn View 1 chunk +1 line, -0 lines 0 comments Download
M webrtc/base/base.gyp View 1 chunk +1 line, -0 lines 0 comments Download
M webrtc/base/base_tests.gyp View 1 chunk +1 line, -0 lines 0 comments Download
A webrtc/base/maybe.h View 1 2 3 4 5 6 7 1 chunk +121 lines, -0 lines 0 comments Download
A webrtc/base/maybe_unittest.cc View 1 2 3 4 5 6 7 1 chunk +485 lines, -0 lines 0 comments Download

Messages

Total messages: 33 (8 generated)
kwiberg-webrtc
Please have a look. I wanted to use this for returning values from functions in ...
5 years, 2 months ago (2015-10-19 11:55:32 UTC) #3
the sun
On 2015/10/19 11:55:32, kwiberg-webrtc wrote: > Please have a look. I wanted to use this ...
5 years, 2 months ago (2015-10-19 12:43:29 UTC) #4
the sun
https://codereview.webrtc.org/1413763003/diff/20001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/20001/webrtc/base/maybe.h#newcode57 webrtc/base/maybe.h:57: Maybe& operator=(const T& val) { if (this != &val) ...
5 years, 2 months ago (2015-10-19 12:43:41 UTC) #5
kwiberg-webrtc
On 2015/10/19 12:43:29, the sun wrote: > On 2015/10/19 11:55:32, kwiberg-webrtc wrote: > > Please ...
5 years, 2 months ago (2015-10-19 12:57:57 UTC) #6
kwiberg-webrtc
https://codereview.webrtc.org/1413763003/diff/20001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/20001/webrtc/base/maybe.h#newcode57 webrtc/base/maybe.h:57: Maybe& operator=(const T& val) { On 2015/10/19 12:43:41, the ...
5 years, 2 months ago (2015-10-19 13:00:07 UTC) #7
the sun
On 2015/10/19 13:00:07, kwiberg-webrtc wrote: > https://codereview.webrtc.org/1413763003/diff/20001/webrtc/base/maybe.h > File webrtc/base/maybe.h (right): > > https://codereview.webrtc.org/1413763003/diff/20001/webrtc/base/maybe.h#newcode57 > ...
5 years, 2 months ago (2015-10-19 14:35:59 UTC) #8
the sun
On 2015/10/19 12:57:57, kwiberg-webrtc wrote: > On 2015/10/19 12:43:29, the sun wrote: > > On ...
5 years, 2 months ago (2015-10-19 14:36:39 UTC) #9
Andrew MacDonald
Nice! The test is really nifty. Just one minor comment. Adding Michael to this CL ...
5 years, 2 months ago (2015-10-20 01:54:30 UTC) #11
mgraczyk
Mostly minor comments, but conversion from T should either be allowed or a comment should ...
5 years, 2 months ago (2015-10-20 02:44:44 UTC) #12
kwiberg-webrtc
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode27 webrtc/base/maybe.h:27: // A moved-from Maybe<T> may only be destroyed. Specifically, ...
5 years, 2 months ago (2015-10-20 08:43:20 UTC) #14
kwiberg-webrtc
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode92 webrtc/base/maybe.h:92: } On 2015/10/20 08:43:20, kwiberg-webrtc wrote: > I was ...
5 years, 2 months ago (2015-10-20 13:35:30 UTC) #16
Andrew MacDonald
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode39 webrtc/base/maybe.h:39: explicit Maybe(const T& val) : value_(val), has_value_(true) {} On ...
5 years, 2 months ago (2015-10-20 18:38:04 UTC) #17
mgraczyk
lgtm. Nice tests. make_maybe would likely be helpful, but is not necessary. https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h ...
5 years, 2 months ago (2015-10-20 19:10:23 UTC) #18
kwiberg-webrtc
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode39 webrtc/base/maybe.h:39: explicit Maybe(const T& val) : value_(val), has_value_(true) {} On ...
5 years, 2 months ago (2015-10-20 21:12:00 UTC) #19
kwiberg-webrtc
On 2015/10/20 19:10:23, mgraczyk wrote: > make_maybe would likely be helpful, but is not necessary. ...
5 years, 2 months ago (2015-10-20 21:14:45 UTC) #20
kwiberg-webrtc
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode56 webrtc/base/maybe.h:56: Maybe& operator=(const T& val) { On 2015/10/20 21:11:59, kwiberg-webrtc ...
5 years, 2 months ago (2015-10-20 21:26:00 UTC) #21
mgraczyk
> Hmm. How useful would it be, really, given implicit conversion from T to Maybe<T>? ...
5 years, 2 months ago (2015-10-20 22:15:59 UTC) #22
mgraczyk
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode56 webrtc/base/maybe.h:56: Maybe& operator=(const T& val) { On 2015/10/20 21:26:00, kwiberg-webrtc ...
5 years, 2 months ago (2015-10-20 22:16:19 UTC) #23
kwiberg-webrtc
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode56 webrtc/base/maybe.h:56: Maybe& operator=(const T& val) { On 2015/10/20 22:16:19, mgraczyk ...
5 years, 2 months ago (2015-10-20 22:57:18 UTC) #24
mgraczyk
https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h File webrtc/base/maybe.h (right): https://codereview.webrtc.org/1413763003/diff/40001/webrtc/base/maybe.h#newcode67 webrtc/base/maybe.h:67: friend void swap(Maybe& m1, Maybe& m2) { On 2015/10/20 ...
5 years, 2 months ago (2015-10-21 00:57:18 UTC) #25
Andrew MacDonald
lgtm
5 years, 2 months ago (2015-10-21 01:27:54 UTC) #26
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1413763003/140001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1413763003/140001
5 years, 2 months ago (2015-10-21 08:44:36 UTC) #29
commit-bot: I haz the power
Try jobs failed on following builders: presubmit on tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/presubmit/builds/1339)
5 years, 2 months ago (2015-10-21 08:46:35 UTC) #31
kwiberg-webrtc
Committed patchset #8 (id:140001) manually as 6e587200db7ddae0d33e5187b73acdd41175584c (presubmit successful).
5 years, 2 months ago (2015-10-21 10:44:24 UTC) #32
commit-bot: I haz the power
5 years, 2 months ago (2015-10-21 10:44:28 UTC) #33
Message was sent while issue was closed.
Patchset 8 (id:??) landed as
https://crrev.com/6e587200db7ddae0d33e5187b73acdd41175584c
Cr-Commit-Position: refs/heads/master@{#10353}

Powered by Google App Engine
This is Rietveld 408576698