14 Commits

Author SHA1 Message Date
terelius
f79dbadc09 Add has_value() and value() methods to rtc::Optional.
These methods have the same behavior as their counterparts in std::optional, except that rtc::Optional::value() requires that the value exists whereas std::optional::value() throws an exception.

BUG=webrtc:7843

Review-Url: https://codereview.webrtc.org/2942203002
Cr-Commit-Position: refs/heads/master@{#18631}
2017-06-16 13:48:13 +00:00
ossu
e5c27a5db6 Add a PrintTo function for rtc::Optional to aid with testing.
gtest can print objects if they have an operator<< or a PrintTo
function in the same namespace as the object's class. Since
std::optional does not seem to have an operator<<, it'd be preferable
not to rely on rtc::Optional being printable through operator<<.

Currently, gtest errors will just dump the raw bytes of
rtc::Optionals, which make them really annoying to work with in tests.

BUG=webrtc:7196

Review-Url: https://codereview.webrtc.org/2704483002
Cr-Commit-Position: refs/heads/master@{#16717}
2017-02-20 12:41:42 +00:00
deadbeef
81baed36bf Add ability to return moved value from FunctorMessageHandler, Optional.
This functionality is desired for this CL:
https://codereview.webrtc.org/2675173003/

BUG=None

Review-Url: https://codereview.webrtc.org/2681283002
Cr-Commit-Position: refs/heads/master@{#16546}
2017-02-11 02:11:11 +00:00
kwiberg
b3f7dbc7a5 Add advice about Optional function arguments
This comes from here:
https://codereview.webrtc.org/2585293002/diff/1/webrtc/modules/audio_coding/audio_network_adaptor/fec_controller.h#newcode91

BUG=none
NOTRY=true

Review-Url: https://codereview.webrtc.org/2624573004
Cr-Commit-Position: refs/heads/master@{#15980}
2017-01-10 10:11:17 +00:00
danilchap
e037060161 Add to rtc::Optional equality/unequality comparisions with object
BUG=None

Review-Url: https://codereview.webrtc.org/2432393002
Cr-Commit-Position: refs/heads/master@{#14690}
2016-10-20 07:58:31 +00:00
danilchap
9e83c97e9f Add rtc::Optional::emplace
BUG=None

Review-Url: https://codereview.webrtc.org/2424063002
Cr-Commit-Position: refs/heads/master@{#14659}
2016-10-18 11:07:25 +00:00
danilchap
c4fd23cdda Add rtc::Optional::reset
BUG=None

Review-Url: https://codereview.webrtc.org/2426473004
Cr-Commit-Position: refs/heads/master@{#14651}
2016-10-17 14:16:57 +00:00
kwiberg
2b11fd2e4b rtc::Optional: Tell sanitizers that unset values aren't OK to access
This is a sample use of the other three sanitizer functions introduced
in https://codereview.webrtc.org/2293893002/.

BUG=chromium:617124

Review-Url: https://codereview.webrtc.org/2289383002
Cr-Commit-Position: refs/heads/master@{#14157}
2016-09-09 10:35:32 +00:00
ossu
ea41694e08 Added an empty member to the union of rtc::Optional, so that it is always initializable.
Added notry due to flaky android_dbg bot.

NOTRY=true
BUG=webrtc:6033

Review-Url: https://codereview.webrtc.org/2090223003
Cr-Commit-Position: refs/heads/master@{#13343}
2016-06-30 09:15:00 +00:00
kwiberg
d040480f69 rtc::Optional<T>: Don't secretly contain a default-constructed T when empty
Instead, use a neat trick with union to ensure that we have a T only
when we're supposed to (and just a bunch of unused memory otherwise).
This is how std::optional behaves, so it makes sense for us to do the
same (and it's convenient, too, since we don't have to pay for the
default-constructed T, and we support types that don't have default
constructors).

Doing this became possible recently when we dropped support for MSVC
2013, which didn't support unions containing non-trivial types.

Review-Url: https://codereview.webrtc.org/1896833004
Cr-Commit-Position: refs/heads/master@{#12664}
2016-05-09 13:06:10 +00:00
kwiberg
bfefb03ec1 Replace scoped_ptr with unique_ptr everywhere
But keep #including scoped_ptr.h in .h files, so as not to break
WebRTC users who expect those .h files to give them rtc::scoped_ptr.

BUG=webrtc:5520

Review-Url: https://codereview.webrtc.org/1937693002
Cr-Commit-Position: refs/heads/master@{#12581}
2016-05-01 21:53:55 +00:00
kwiberg
6ca0a31708 We no longer use compilers that can't =default move construction and assignment
Review URL: https://codereview.webrtc.org/1891483006

Cr-Commit-Position: refs/heads/master@{#12376}
2016-04-15 12:25:03 +00:00
kwiberg
cea7c2f783 Replace manual casting to rvalue reference with calls to std::move
Review URL: https://codereview.webrtc.org/1570473002

Cr-Commit-Position: refs/heads/master@{#11163}
2016-01-07 13:52:09 +00:00
Karl Wiberg
be57983f4b Rename Maybe to Optional
And add examples of good and bad usage to the documentation.

R=aluebs@webrtc.org, henrik.lundin@webrtc.org, pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/1432553007 .

Cr-Commit-Position: refs/heads/master@{#10588}
2015-11-10 21:34:32 +00:00