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}
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}
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}
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}