Commit c3015ed0 authored by TJ Yin's avatar TJ Yin Committed by Facebook Github Bot

Replace folly::Optional::hasValue() by has_value()

Differential Revision: D19882830

fbshipit-source-id: 031217f9890351022bc8d171f0ccd7e045dd6972
parent 68c24721
...@@ -700,7 +700,7 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress( ...@@ -700,7 +700,7 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress(
} }
} else { } else {
// Invariants // Invariants
DCHECK(uncompressedLength.hasValue()); DCHECK(uncompressedLength.has_value());
DCHECK(*uncompressedLength <= maxUncompressedLength()); DCHECK(*uncompressedLength <= maxUncompressedLength());
actualUncompressedLength = *uncompressedLength; actualUncompressedLength = *uncompressedLength;
} }
......
...@@ -342,7 +342,7 @@ bool ZlibStreamCodec::doCompressStream( ...@@ -342,7 +342,7 @@ bool ZlibStreamCodec::doCompressStream(
resetDeflateStream(); resetDeflateStream();
needReset_ = false; needReset_ = false;
} }
DCHECK(deflateStream_.hasValue()); DCHECK(deflateStream_.has_value());
// zlib will return Z_STREAM_ERROR if output.data() is null. // zlib will return Z_STREAM_ERROR if output.data() is null.
if (output.data() == nullptr) { if (output.data() == nullptr) {
return false; return false;
...@@ -377,7 +377,7 @@ bool ZlibStreamCodec::doUncompressStream( ...@@ -377,7 +377,7 @@ bool ZlibStreamCodec::doUncompressStream(
resetInflateStream(); resetInflateStream();
needReset_ = false; needReset_ = false;
} }
DCHECK(inflateStream_.hasValue()); DCHECK(inflateStream_.has_value());
// zlib will return Z_STREAM_ERROR if output.data() is null. // zlib will return Z_STREAM_ERROR if output.data() is null.
if (output.data() == nullptr) { if (output.data() == nullptr) {
return false; return false;
......
...@@ -470,7 +470,7 @@ TEST(Util, callWithConstructedKey) { ...@@ -470,7 +470,7 @@ TEST(Util, callWithConstructedKey) {
// very useful in real life. Verify that it works. // very useful in real life. Verify that it works.
sink.reset(); sink.reset();
detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc); detail::callWithConstructedKey<Tracked<0>, FalseFunc1>(a, sinkFunc);
EXPECT_TRUE(sink.hasValue()); EXPECT_TRUE(sink.has_value());
} }
// We're deliberately allowing only a subset of the desired heterogeneous // We're deliberately allowing only a subset of the desired heterogeneous
......
...@@ -38,7 +38,7 @@ serialization_opts::serialization_opts() ...@@ -38,7 +38,7 @@ serialization_opts::serialization_opts()
static const dynamic* getTemplate( static const dynamic* getTemplate(
const serialization_opts& opts, const serialization_opts& opts,
dynamic const& dynArray) { dynamic const& dynArray) {
if (!opts.templates.hasValue()) { if (!opts.templates.has_value()) {
return nullptr; return nullptr;
} }
const auto& templates = opts.templates.value(); const auto& templates = opts.templates.value();
......
...@@ -98,7 +98,7 @@ TEST(Settings, user_defined) { ...@@ -98,7 +98,7 @@ TEST(Settings, user_defined) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto info = sn.getAsString("follytest_user_defined"); auto info = sn.getAsString("follytest_user_defined");
EXPECT_TRUE(info.hasValue()); EXPECT_TRUE(info.has_value());
EXPECT_EQ(info->first, "a_out"); EXPECT_EQ(info->first, "a_out");
EXPECT_EQ(info->second, "test"); EXPECT_EQ(info->second, "test");
} }
...@@ -113,7 +113,7 @@ TEST(Settings, user_defined) { ...@@ -113,7 +113,7 @@ TEST(Settings, user_defined) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto info = sn.getAsString("follytest_user_defined"); auto info = sn.getAsString("follytest_user_defined");
EXPECT_TRUE(info.hasValue()); EXPECT_TRUE(info.has_value());
EXPECT_EQ(info->first, "a_out"); EXPECT_EQ(info->first, "a_out");
EXPECT_EQ(info->second, "test"); EXPECT_EQ(info->second, "test");
} }
...@@ -126,7 +126,7 @@ TEST(Settings, user_defined) { ...@@ -126,7 +126,7 @@ TEST(Settings, user_defined) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto info = sn.getAsString("follytest_user_defined"); auto info = sn.getAsString("follytest_user_defined");
EXPECT_TRUE(info.hasValue()); EXPECT_TRUE(info.has_value());
EXPECT_EQ(info->first, "b_out"); EXPECT_EQ(info->first, "b_out");
EXPECT_EQ(info->second, "default"); EXPECT_EQ(info->second, "default");
} }
...@@ -140,7 +140,7 @@ TEST(Settings, user_defined) { ...@@ -140,7 +140,7 @@ TEST(Settings, user_defined) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto info = sn.getAsString("follytest_user_defined"); auto info = sn.getAsString("follytest_user_defined");
EXPECT_TRUE(info.hasValue()); EXPECT_TRUE(info.has_value());
EXPECT_EQ(info->first, "b_out"); EXPECT_EQ(info->first, "b_out");
EXPECT_EQ(info->second, "default"); EXPECT_EQ(info->second, "default");
} }
...@@ -161,13 +161,13 @@ TEST(Settings, basic) { ...@@ -161,13 +161,13 @@ TEST(Settings, basic) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto res = sn.getAsString("follytest_public_flag_to_a"); auto res = sn.getAsString("follytest_public_flag_to_a");
EXPECT_TRUE(res.hasValue()); EXPECT_TRUE(res.has_value());
EXPECT_EQ(res->first, "200"); EXPECT_EQ(res->first, "200");
EXPECT_EQ(res->second, "remote_set"); EXPECT_EQ(res->second, "remote_set");
} }
{ {
auto meta = folly::settings::getSettingsMeta("follytest_public_flag_to_a"); auto meta = folly::settings::getSettingsMeta("follytest_public_flag_to_a");
EXPECT_TRUE(meta.hasValue()); EXPECT_TRUE(meta.has_value());
const auto& md = meta.value(); const auto& md = meta.value();
EXPECT_EQ(md.project, "follytest"); EXPECT_EQ(md.project, "follytest");
EXPECT_EQ(md.name, "public_flag_to_a"); EXPECT_EQ(md.name, "public_flag_to_a");
...@@ -176,7 +176,7 @@ TEST(Settings, basic) { ...@@ -176,7 +176,7 @@ TEST(Settings, basic) {
} }
{ {
auto meta = folly::settings::getSettingsMeta("follytest_some_flag"); auto meta = folly::settings::getSettingsMeta("follytest_some_flag");
EXPECT_TRUE(meta.hasValue()); EXPECT_TRUE(meta.has_value());
const auto& md = meta.value(); const auto& md = meta.value();
EXPECT_EQ(md.project, "follytest"); EXPECT_EQ(md.project, "follytest");
EXPECT_EQ(md.name, "some_flag"); EXPECT_EQ(md.name, "some_flag");
...@@ -186,7 +186,7 @@ TEST(Settings, basic) { ...@@ -186,7 +186,7 @@ TEST(Settings, basic) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto res = sn.getAsString("follytest_nonexisting"); auto res = sn.getAsString("follytest_nonexisting");
EXPECT_FALSE(res.hasValue()); EXPECT_FALSE(res.has_value());
} }
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
...@@ -199,7 +199,7 @@ TEST(Settings, basic) { ...@@ -199,7 +199,7 @@ TEST(Settings, basic) {
{ {
folly::settings::Snapshot sn; folly::settings::Snapshot sn;
auto res = sn.getAsString("follytest_public_flag_to_a"); auto res = sn.getAsString("follytest_public_flag_to_a");
EXPECT_TRUE(res.hasValue()); EXPECT_TRUE(res.has_value());
EXPECT_EQ(res->first, "300"); EXPECT_EQ(res->first, "300");
EXPECT_EQ(res->second, "from_string"); EXPECT_EQ(res->second, "from_string");
} }
......
...@@ -1113,8 +1113,8 @@ TEST(FiberManager, remoteFiberBasic) { ...@@ -1113,8 +1113,8 @@ TEST(FiberManager, remoteFiberBasic) {
manager.loopUntilNoReady(); manager.loopUntilNoReady();
EXPECT_TRUE(savedPromise[0].hasValue()); EXPECT_TRUE(savedPromise[0].has_value());
EXPECT_TRUE(savedPromise[1].hasValue()); EXPECT_TRUE(savedPromise[1].has_value());
EXPECT_EQ(0, result[0]); EXPECT_EQ(0, result[0]);
EXPECT_EQ(0, result[1]); EXPECT_EQ(0, result[1]);
...@@ -1156,8 +1156,8 @@ TEST(FiberManager, addTaskRemoteBasic) { ...@@ -1156,8 +1156,8 @@ TEST(FiberManager, addTaskRemoteBasic) {
manager.loopUntilNoReady(); manager.loopUntilNoReady();
EXPECT_TRUE(savedPromise[0].hasValue()); EXPECT_TRUE(savedPromise[0].has_value());
EXPECT_TRUE(savedPromise[1].hasValue()); EXPECT_TRUE(savedPromise[1].has_value());
EXPECT_EQ(0, result[0]); EXPECT_EQ(0, result[0]);
EXPECT_EQ(0, result[1]); EXPECT_EQ(0, result[1]);
......
...@@ -29,7 +29,7 @@ TEST(Poll, ready) { ...@@ -29,7 +29,7 @@ TEST(Poll, ready) {
TEST(Poll, notReady) { TEST(Poll, notReady) {
Promise<int> p; Promise<int> p;
auto f = p.getFuture(); auto f = p.getFuture();
EXPECT_FALSE(f.poll().hasValue()); EXPECT_FALSE(f.poll().has_value());
} }
TEST(Poll, exception) { TEST(Poll, exception) {
......
...@@ -491,7 +491,7 @@ TEST(Gen, Composed) { ...@@ -491,7 +491,7 @@ TEST(Gen, Composed) {
// Operator, Operator // Operator, Operator
// clang-format off // clang-format off
auto valuesOf auto valuesOf
= filter([](Optional<int>& o) { return o.hasValue(); }) = filter([](Optional<int>& o) { return o.has_value(); })
| map([](Optional<int>& o) -> int& { return o.value(); }); | map([](Optional<int>& o) -> int& { return o.value(); });
// clang-format on // clang-format on
std::vector<Optional<int>> opts{none, 4, none, 6, none}; std::vector<Optional<int>> opts{none, 4, none, 6, none};
...@@ -1378,13 +1378,13 @@ TEST(Gen, Unwrap) { ...@@ -1378,13 +1378,13 @@ TEST(Gen, Unwrap) {
// optional has a value, and that value is non-null // optional has a value, and that value is non-null
EXPECT_TRUE(bool(oup | unwrap)); EXPECT_TRUE(bool(oup | unwrap));
EXPECT_EQ(5, *(oup | unwrap)); EXPECT_EQ(5, *(oup | unwrap));
EXPECT_TRUE(oup.hasValue()); // still has a pointer (null or not) EXPECT_TRUE(oup.has_value()); // still has a pointer (null or not)
EXPECT_TRUE(bool(oup.value())); // that value isn't null EXPECT_TRUE(bool(oup.value())); // that value isn't null
auto moved1 = std::move(oup) | unwrapOr(std::make_unique<int>(6)); auto moved1 = std::move(oup) | unwrapOr(std::make_unique<int>(6));
// oup still has a value, but now it's now nullptr since the pointer was moved // oup still has a value, but now it's now nullptr since the pointer was moved
// into moved1 // into moved1
EXPECT_TRUE(oup.hasValue()); EXPECT_TRUE(oup.has_value());
EXPECT_FALSE(oup.value()); EXPECT_FALSE(oup.value());
EXPECT_TRUE(bool(moved1)); EXPECT_TRUE(bool(moved1));
EXPECT_EQ(5, *moved1); EXPECT_EQ(5, *moved1);
......
...@@ -742,7 +742,7 @@ bool AsyncUDPSocket::setGSO(int val) { ...@@ -742,7 +742,7 @@ bool AsyncUDPSocket::setGSO(int val) {
int AsyncUDPSocket::getGSO() { int AsyncUDPSocket::getGSO() {
// check if we can return the cached value // check if we can return the cached value
if (FOLLY_UNLIKELY(!gso_.hasValue())) { if (FOLLY_UNLIKELY(!gso_.has_value())) {
#ifdef FOLLY_HAVE_MSG_ERRQUEUE #ifdef FOLLY_HAVE_MSG_ERRQUEUE
int gso = -1; int gso = -1;
socklen_t optlen = sizeof(gso); socklen_t optlen = sizeof(gso);
......
...@@ -512,16 +512,16 @@ class NextProtocolTest : public Test { ...@@ -512,16 +512,16 @@ class NextProtocolTest : public Test {
} }
void expectHandshakeSuccess() { void expectHandshakeSuccess() {
EXPECT_FALSE(client->except.hasValue()) EXPECT_FALSE(client->except.has_value())
<< "client handshake error: " << client->except->what(); << "client handshake error: " << client->except->what();
EXPECT_FALSE(server->except.hasValue()) EXPECT_FALSE(server->except.has_value())
<< "server handshake error: " << server->except->what(); << "server handshake error: " << server->except->what();
} }
void expectHandshakeError() { void expectHandshakeError() {
EXPECT_TRUE(client->except.hasValue()) EXPECT_TRUE(client->except.has_value())
<< "Expected client handshake error!"; << "Expected client handshake error!";
EXPECT_TRUE(server->except.hasValue()) EXPECT_TRUE(server->except.has_value())
<< "Expected server handshake error!"; << "Expected server handshake error!";
} }
......
...@@ -3200,10 +3200,10 @@ TEST_P(AsyncSocketErrMessageCallbackTest, ErrMessageCallback) { ...@@ -3200,10 +3200,10 @@ TEST_P(AsyncSocketErrMessageCallbackTest, ErrMessageCallback) {
// set the number of error messages before socket is closed or callback reset // set the number of error messages before socket is closed or callback reset
const auto testParams = GetParam(); const auto testParams = GetParam();
errMsgCB.socket_ = socket.get(); errMsgCB.socket_ = socket.get();
if (testParams.resetCallbackAfter.hasValue()) { if (testParams.resetCallbackAfter.has_value()) {
errMsgCB.resetCallbackAfter_ = testParams.resetCallbackAfter.value(); errMsgCB.resetCallbackAfter_ = testParams.resetCallbackAfter.value();
} }
if (testParams.closeSocketAfter.hasValue()) { if (testParams.closeSocketAfter.has_value()) {
errMsgCB.closeSocketAfter_ = testParams.closeSocketAfter.value(); errMsgCB.closeSocketAfter_ = testParams.closeSocketAfter.value();
} }
......
...@@ -59,7 +59,7 @@ class BlockingSocket : public folly::AsyncSocket::ConnectCallback, ...@@ -59,7 +59,7 @@ class BlockingSocket : public folly::AsyncSocket::ConnectCallback,
DCHECK_LE(timeout.count(), std::numeric_limits<int>::max()); DCHECK_LE(timeout.count(), std::numeric_limits<int>::max());
sock_->connect(this, address_, folly::to_narrow(timeout.count())); sock_->connect(this, address_, folly::to_narrow(timeout.count()));
eventBase_.loop(); eventBase_.loop();
if (err_.hasValue()) { if (err_.has_value()) {
throw err_.value(); throw err_.value();
} }
} }
...@@ -77,7 +77,7 @@ class BlockingSocket : public folly::AsyncSocket::ConnectCallback, ...@@ -77,7 +77,7 @@ class BlockingSocket : public folly::AsyncSocket::ConnectCallback,
folly::WriteFlags flags = folly::WriteFlags::NONE) { folly::WriteFlags flags = folly::WriteFlags::NONE) {
sock_->write(this, buf, len, flags); sock_->write(this, buf, len, flags);
eventBase_.loop(); eventBase_.loop();
if (err_.hasValue()) { if (err_.has_value()) {
throw err_.value(); throw err_.value();
} }
return folly::to_narrow(folly::to_signed(len)); return folly::to_narrow(folly::to_signed(len));
...@@ -154,7 +154,7 @@ class BlockingSocket : public folly::AsyncSocket::ConnectCallback, ...@@ -154,7 +154,7 @@ class BlockingSocket : public folly::AsyncSocket::ConnectCallback,
} }
} }
sock_->setReadCB(nullptr); sock_->setReadCB(nullptr);
if (err_.hasValue()) { if (err_.has_value()) {
throw err_.value(); throw err_.value();
} }
if (all && readLen_ > 0) { if (all && readLen_ > 0) {
......
...@@ -266,7 +266,7 @@ json_patch::apply(dynamic& obj) { ...@@ -266,7 +266,7 @@ json_patch::apply(dynamic& obj) {
break; break;
} }
case op_code::add: { case op_code::add: {
DCHECK(op.value.hasValue()); DCHECK(op.value.has_value());
auto ret = do_add(resolved_path, *op.value, op.path.tokens().back()); auto ret = do_add(resolved_path, *op.value, op.path.tokens().back());
if (ret.hasError()) { if (ret.hasError()) {
return makeUnexpected(error{ret.error(), index}); return makeUnexpected(error{ret.error(), index});
...@@ -283,7 +283,7 @@ json_patch::apply(dynamic& obj) { ...@@ -283,7 +283,7 @@ json_patch::apply(dynamic& obj) {
break; break;
} }
case op_code::move: { case op_code::move: {
DCHECK(op.from.hasValue()); DCHECK(op.from.has_value());
auto resolved_from = obj.try_get_ptr(*op.from); auto resolved_from = obj.try_get_ptr(*op.from);
if (!resolved_from.hasValue()) { if (!resolved_from.hasValue()) {
return makeUnexpected(error{error_code::from_not_found, index}); return makeUnexpected(error{error_code::from_not_found, index});
...@@ -304,7 +304,7 @@ json_patch::apply(dynamic& obj) { ...@@ -304,7 +304,7 @@ json_patch::apply(dynamic& obj) {
break; break;
} }
case op_code::copy: { case op_code::copy: {
DCHECK(op.from.hasValue()); DCHECK(op.from.has_value());
auto const resolved_from = obj.try_get_ptr(*op.from); auto const resolved_from = obj.try_get_ptr(*op.from);
if (!resolved_from.hasValue()) { if (!resolved_from.hasValue()) {
return makeUnexpected(error{error_code::from_not_found, index}); return makeUnexpected(error{error_code::from_not_found, index});
......
...@@ -46,12 +46,12 @@ std::shared_ptr<LogWriter> FileWriterFactory::createWriter(File file) { ...@@ -46,12 +46,12 @@ std::shared_ptr<LogWriter> FileWriterFactory::createWriter(File file) {
// Determine whether we should use ImmediateFileWriter or AsyncFileWriter // Determine whether we should use ImmediateFileWriter or AsyncFileWriter
if (async_) { if (async_) {
auto asyncWriter = make_shared<AsyncFileWriter>(std::move(file)); auto asyncWriter = make_shared<AsyncFileWriter>(std::move(file));
if (maxBufferSize_.hasValue()) { if (maxBufferSize_.has_value()) {
asyncWriter->setMaxBufferSize(maxBufferSize_.value()); asyncWriter->setMaxBufferSize(maxBufferSize_.value());
} }
return asyncWriter; return asyncWriter;
} else { } else {
if (maxBufferSize_.hasValue()) { if (maxBufferSize_.has_value()) {
throw std::invalid_argument(to<string>( throw std::invalid_argument(to<string>(
"the \"max_buffer_size\" option is only valid for async file " "the \"max_buffer_size\" option is only valid for async file "
"handlers")); "handlers"));
......
...@@ -33,7 +33,7 @@ void LogConfig::update(const LogConfig& other) { ...@@ -33,7 +33,7 @@ void LogConfig::update(const LogConfig& other) {
// Update handlerConfigs_ with all of the entries from the other LogConfig. // Update handlerConfigs_ with all of the entries from the other LogConfig.
// Any entries already present in our handlerConfigs_ are replaced wholesale. // Any entries already present in our handlerConfigs_ are replaced wholesale.
for (const auto& entry : other.handlerConfigs_) { for (const auto& entry : other.handlerConfigs_) {
if (entry.second.type.hasValue()) { if (entry.second.type.has_value()) {
// This is a complete LogHandlerConfig that should be inserted // This is a complete LogHandlerConfig that should be inserted
// or completely replace an existing handler config with this name. // or completely replace an existing handler config with this name.
auto result = handlerConfigs_.insert(entry); auto result = handlerConfigs_.insert(entry);
...@@ -65,7 +65,7 @@ void LogConfig::update(const LogConfig& other) { ...@@ -65,7 +65,7 @@ void LogConfig::update(const LogConfig& other) {
auto* existingEntry = &result.first->second; auto* existingEntry = &result.first->second;
auto oldHandlers = std::move(existingEntry->handlers); auto oldHandlers = std::move(existingEntry->handlers);
*existingEntry = entry.second; *existingEntry = entry.second;
if (!existingEntry->handlers.hasValue()) { if (!existingEntry->handlers.has_value()) {
existingEntry->handlers = std::move(oldHandlers); existingEntry->handlers = std::move(oldHandlers);
} }
} }
......
...@@ -402,7 +402,7 @@ std::pair<std::string, LogHandlerConfig> parseHandlerConfig(StringPiece value) { ...@@ -402,7 +402,7 @@ std::pair<std::string, LogHandlerConfig> parseHandlerConfig(StringPiece value) {
handlerName, handlerName,
"\": name cannot contain a comma when using the basic config format")}; "\": name cannot contain a comma when using the basic config format")};
} }
if (handlerType.hasValue()) { if (handlerType.has_value()) {
if (handlerType->empty()) { if (handlerType->empty()) {
throw LogConfigParseError{to<string>( throw LogConfigParseError{to<string>(
"error parsing configuration for log handler \"", "error parsing configuration for log handler \"",
...@@ -584,7 +584,7 @@ dynamic logConfigToDynamic(const LogHandlerConfig& config) { ...@@ -584,7 +584,7 @@ dynamic logConfigToDynamic(const LogHandlerConfig& config) {
options.insert(opt.first, opt.second); options.insert(opt.first, opt.second);
} }
auto result = dynamic::object("options", options); auto result = dynamic::object("options", options);
if (config.type.hasValue()) { if (config.type.has_value()) {
result("type", config.type.value()); result("type", config.type.value());
} }
return result; return result;
...@@ -594,7 +594,7 @@ dynamic logConfigToDynamic(const LogCategoryConfig& config) { ...@@ -594,7 +594,7 @@ dynamic logConfigToDynamic(const LogCategoryConfig& config) {
auto value = dynamic::object("level", logLevelToString(config.level))( auto value = dynamic::object("level", logLevelToString(config.level))(
"inherit", config.inheritParentLevel)( "inherit", config.inheritParentLevel)(
"propagate", logLevelToString(config.propagateLevelMessagesToParent)); "propagate", logLevelToString(config.propagateLevelMessagesToParent));
if (config.handlers.hasValue()) { if (config.handlers.has_value()) {
auto handlers = dynamic::array(); auto handlers = dynamic::array();
for (const auto& handlerName : config.handlers.value()) { for (const auto& handlerName : config.handlers.value()) {
handlers.push_back(handlerName); handlers.push_back(handlerName);
......
...@@ -27,18 +27,18 @@ LogHandlerConfig::LogHandlerConfig() = default; ...@@ -27,18 +27,18 @@ LogHandlerConfig::LogHandlerConfig() = default;
LogHandlerConfig::LogHandlerConfig(StringPiece t) : type{t.str()} {} LogHandlerConfig::LogHandlerConfig(StringPiece t) : type{t.str()} {}
LogHandlerConfig::LogHandlerConfig(Optional<StringPiece> t) LogHandlerConfig::LogHandlerConfig(Optional<StringPiece> t)
: type{t.hasValue() ? Optional<string>{t->str()} : Optional<string>{}} {} : type{t.has_value() ? Optional<string>{t->str()} : Optional<string>{}} {}
LogHandlerConfig::LogHandlerConfig(StringPiece t, Options opts) LogHandlerConfig::LogHandlerConfig(StringPiece t, Options opts)
: type{t.str()}, options{std::move(opts)} {} : type{t.str()}, options{std::move(opts)} {}
LogHandlerConfig::LogHandlerConfig(Optional<StringPiece> t, Options opts) LogHandlerConfig::LogHandlerConfig(Optional<StringPiece> t, Options opts)
: type{t.hasValue() ? Optional<string>{t->str()} : Optional<string>{}}, : type{t.has_value() ? Optional<string>{t->str()} : Optional<string>{}},
options{std::move(opts)} {} options{std::move(opts)} {}
void LogHandlerConfig::update(const LogHandlerConfig& other) { void LogHandlerConfig::update(const LogHandlerConfig& other) {
FOLLY_SAFE_DCHECK( FOLLY_SAFE_DCHECK(
!other.type.hasValue(), "LogHandlerConfig type cannot be updated"); !other.type.has_value(), "LogHandlerConfig type cannot be updated");
for (const auto& option : other.options) { for (const auto& option : other.options) {
options[option.first] = option.second; options[option.first] = option.second;
} }
......
...@@ -217,7 +217,7 @@ void LoggerDB::startConfigUpdate( ...@@ -217,7 +217,7 @@ void LoggerDB::startConfigUpdate(
LogHandlerConfig updatedConfig; LogHandlerConfig updatedConfig;
const LogHandlerConfig* handlerConfig; const LogHandlerConfig* handlerConfig;
if (entry.second.type.hasValue()) { if (entry.second.type.has_value()) {
handlerConfig = &entry.second; handlerConfig = &entry.second;
} else { } else {
// This configuration is intended to update an existing LogHandler // This configuration is intended to update an existing LogHandler
...@@ -227,7 +227,7 @@ void LoggerDB::startConfigUpdate( ...@@ -227,7 +227,7 @@ void LoggerDB::startConfigUpdate(
} }
updatedConfig = oldHandler->getConfig(); updatedConfig = oldHandler->getConfig();
if (!updatedConfig.type.hasValue()) { if (!updatedConfig.type.has_value()) {
// This normally should not happen unless someone improperly manually // This normally should not happen unless someone improperly manually
// constructed a LogHandler object. All existing LogHandler objects // constructed a LogHandler object. All existing LogHandler objects
// should indicate their type. // should indicate their type.
...@@ -279,7 +279,7 @@ void LoggerDB::startConfigUpdate( ...@@ -279,7 +279,7 @@ void LoggerDB::startConfigUpdate(
// Before we start making any LogCategory changes, confirm that all handlers // Before we start making any LogCategory changes, confirm that all handlers
// named in the category configs are known handlers. // named in the category configs are known handlers.
for (const auto& entry : config.getCategoryConfigs()) { for (const auto& entry : config.getCategoryConfigs()) {
if (!entry.second.handlers.hasValue()) { if (!entry.second.handlers.has_value()) {
continue; continue;
} }
for (const auto& handlerName : entry.second.handlers.value()) { for (const auto& handlerName : entry.second.handlers.value()) {
...@@ -374,7 +374,7 @@ void LoggerDB::updateConfig(const LogConfig& config) { ...@@ -374,7 +374,7 @@ void LoggerDB::updateConfig(const LogConfig& config) {
getOrCreateCategoryLocked(*loggersByName, entry.first); getOrCreateCategoryLocked(*loggersByName, entry.first);
// Update the log handlers // Update the log handlers
if (entry.second.handlers.hasValue()) { if (entry.second.handlers.has_value()) {
auto catHandlers = buildCategoryHandlerList( auto catHandlers = buildCategoryHandlerList(
handlers, entry.first, entry.second.handlers.value()); handlers, entry.first, entry.second.handlers.value());
category->replaceHandlers(std::move(catHandlers)); category->replaceHandlers(std::move(catHandlers));
...@@ -442,7 +442,7 @@ void LoggerDB::resetConfig(const LogConfig& config) { ...@@ -442,7 +442,7 @@ void LoggerDB::resetConfig(const LogConfig& config) {
// If the handler list is not set in the config, clear out any existing // If the handler list is not set in the config, clear out any existing
// handlers rather than leaving it as-is. // handlers rather than leaving it as-is.
std::vector<std::shared_ptr<LogHandler>> catHandlers; std::vector<std::shared_ptr<LogHandler>> catHandlers;
if (catConfig.handlers.hasValue()) { if (catConfig.handlers.has_value()) {
catHandlers = buildCategoryHandlerList( catHandlers = buildCategoryHandlerList(
handlers, entry.first, catConfig.handlers.value()); handlers, entry.first, catConfig.handlers.value());
} }
......
...@@ -68,7 +68,7 @@ std::ostream& operator<<(std::ostream& os, const LogCategoryConfig& config) { ...@@ -68,7 +68,7 @@ std::ostream& operator<<(std::ostream& os, const LogCategoryConfig& config) {
if (config.propagateLevelMessagesToParent > LogLevel::MIN_LEVEL) { if (config.propagateLevelMessagesToParent > LogLevel::MIN_LEVEL) {
os << "[" << config.propagateLevelMessagesToParent << "]"; os << "[" << config.propagateLevelMessagesToParent << "]";
} }
if (config.handlers.hasValue()) { if (config.handlers.has_value()) {
os << ":" << join(",", config.handlers.value()); os << ":" << join(",", config.handlers.value());
} }
return os; return os;
......
...@@ -1249,33 +1249,33 @@ TEST(IPAddress, StringFormat) { ...@@ -1249,33 +1249,33 @@ TEST(IPAddress, StringFormat) {
TEST(IPAddress, getMacAddressFromLinkLocal) { TEST(IPAddress, getMacAddressFromLinkLocal) {
IPAddressV6 ip6("fe80::f652:14ff:fec5:74d8"); IPAddressV6 ip6("fe80::f652:14ff:fec5:74d8");
EXPECT_TRUE(ip6.getMacAddressFromLinkLocal().hasValue()); EXPECT_TRUE(ip6.getMacAddressFromLinkLocal().has_value());
EXPECT_EQ("f4:52:14:c5:74:d8", ip6.getMacAddressFromLinkLocal()->toString()); EXPECT_EQ("f4:52:14:c5:74:d8", ip6.getMacAddressFromLinkLocal()->toString());
} }
TEST(IPAddress, getMacAddressFromLinkLocal_Negative) { TEST(IPAddress, getMacAddressFromLinkLocal_Negative) {
IPAddressV6 no_link_local_ip6("2803:6082:a2:4447::1"); IPAddressV6 no_link_local_ip6("2803:6082:a2:4447::1");
EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue()); EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().has_value());
no_link_local_ip6 = IPAddressV6("fe80::f652:14ff:ccc5:74d8"); no_link_local_ip6 = IPAddressV6("fe80::f652:14ff:ccc5:74d8");
EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue()); EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().has_value());
no_link_local_ip6 = IPAddressV6("fe80::f652:14ff:ffc5:74d8"); no_link_local_ip6 = IPAddressV6("fe80::f652:14ff:ffc5:74d8");
EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue()); EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().has_value());
no_link_local_ip6 = IPAddressV6("fe81::f652:14ff:ffc5:74d8"); no_link_local_ip6 = IPAddressV6("fe81::f652:14ff:ffc5:74d8");
EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().hasValue()); EXPECT_FALSE(no_link_local_ip6.getMacAddressFromLinkLocal().has_value());
} }
TEST(IPAddress, getMacAddressFromEUI64) { TEST(IPAddress, getMacAddressFromEUI64) {
IPAddressV6 ip6("2401:db00:3020:51dc:4a57:ddff:fe04:5643"); IPAddressV6 ip6("2401:db00:3020:51dc:4a57:ddff:fe04:5643");
EXPECT_TRUE(ip6.getMacAddressFromEUI64().hasValue()); EXPECT_TRUE(ip6.getMacAddressFromEUI64().has_value());
EXPECT_EQ("48:57:dd:04:56:43", ip6.getMacAddressFromEUI64()->toString()); EXPECT_EQ("48:57:dd:04:56:43", ip6.getMacAddressFromEUI64()->toString());
ip6 = IPAddressV6("fe80::4a57:ddff:fe04:5643"); ip6 = IPAddressV6("fe80::4a57:ddff:fe04:5643");
EXPECT_TRUE(ip6.getMacAddressFromEUI64().hasValue()); EXPECT_TRUE(ip6.getMacAddressFromEUI64().has_value());
EXPECT_EQ("48:57:dd:04:56:43", ip6.getMacAddressFromEUI64()->toString()); EXPECT_EQ("48:57:dd:04:56:43", ip6.getMacAddressFromEUI64()->toString());
} }
TEST(IPAddress, getMacAddressFromEUI64_Negative) { TEST(IPAddress, getMacAddressFromEUI64_Negative) {
IPAddressV6 not_eui64_ip6("2401:db00:3020:51dc:face:0000:009a:0000"); IPAddressV6 not_eui64_ip6("2401:db00:3020:51dc:face:0000:009a:0000");
EXPECT_FALSE(not_eui64_ip6.getMacAddressFromEUI64().hasValue()); EXPECT_FALSE(not_eui64_ip6.getMacAddressFromEUI64().has_value());
} }
TEST(IPAddress, LongestCommonPrefix) { TEST(IPAddress, LongestCommonPrefix) {
......
...@@ -65,9 +65,9 @@ TEST(MapUtil, get_or_throw_specified) { ...@@ -65,9 +65,9 @@ TEST(MapUtil, get_or_throw_specified) {
TEST(MapUtil, get_optional) { TEST(MapUtil, get_optional) {
std::map<int, int> m; std::map<int, int> m;
m[1] = 2; m[1] = 2;
EXPECT_TRUE(get_optional(m, 1).hasValue()); EXPECT_TRUE(get_optional(m, 1).has_value());
EXPECT_EQ(2, get_optional(m, 1).value()); EXPECT_EQ(2, get_optional(m, 1).value());
EXPECT_FALSE(get_optional(m, 2).hasValue()); EXPECT_FALSE(get_optional(m, 2).has_value());
} }
TEST(MapUtil, get_optional_path_simple) { TEST(MapUtil, get_optional_path_simple) {
......
...@@ -44,7 +44,7 @@ TEST(Optional, CoroutineSuccess) { ...@@ -44,7 +44,7 @@ TEST(Optional, CoroutineSuccess) {
EXPECT_EQ((int)(2.0 * 7 + 7), *z); EXPECT_EQ((int)(2.0 * 7 + 7), *z);
co_return* z; co_return* z;
}(); }();
EXPECT_TRUE(r0.hasValue()); EXPECT_TRUE(r0.has_value());
EXPECT_EQ(21, *r0); EXPECT_EQ(21, *r0);
} }
...@@ -60,7 +60,7 @@ TEST(Optional, CoroutineFailure) { ...@@ -60,7 +60,7 @@ TEST(Optional, CoroutineFailure) {
ADD_FAILURE(); ADD_FAILURE();
co_return z; co_return z;
}(); }();
EXPECT_TRUE(!r1.hasValue()); EXPECT_TRUE(!r1.has_value());
} }
Optional<int> throws() { Optional<int> throws() {
...@@ -94,7 +94,7 @@ TEST(Optional, CoroutineCleanedUp) { ...@@ -94,7 +94,7 @@ TEST(Optional, CoroutineCleanedUp) {
ADD_FAILURE() << "Should not be resuming"; ADD_FAILURE() << "Should not be resuming";
co_return x; co_return x;
}(); }();
EXPECT_FALSE(r.hasValue()); EXPECT_FALSE(r.has_value());
EXPECT_EQ(1, count_dest); EXPECT_EQ(1, count_dest);
} }
......
...@@ -346,26 +346,26 @@ TEST(Optional, Swap) { ...@@ -346,26 +346,26 @@ TEST(Optional, Swap) {
Optional<std::string> b; Optional<std::string> b;
swap(a, b); swap(a, b);
EXPECT_FALSE(a.hasValue()); EXPECT_FALSE(a.has_value());
EXPECT_FALSE(b.hasValue()); EXPECT_FALSE(b.has_value());
a = "hello"; a = "hello";
EXPECT_TRUE(a.hasValue()); EXPECT_TRUE(a.has_value());
EXPECT_FALSE(b.hasValue()); EXPECT_FALSE(b.has_value());
EXPECT_EQ("hello", a.value()); EXPECT_EQ("hello", a.value());
swap(a, b); swap(a, b);
EXPECT_FALSE(a.hasValue()); EXPECT_FALSE(a.has_value());
EXPECT_TRUE(b.hasValue()); EXPECT_TRUE(b.has_value());
EXPECT_EQ("hello", b.value()); EXPECT_EQ("hello", b.value());
a = "bye"; a = "bye";
EXPECT_TRUE(a.hasValue()); EXPECT_TRUE(a.has_value());
EXPECT_EQ("bye", a.value()); EXPECT_EQ("bye", a.value());
swap(a, b); swap(a, b);
EXPECT_TRUE(a.hasValue()); EXPECT_TRUE(a.has_value());
EXPECT_TRUE(b.hasValue()); EXPECT_TRUE(b.has_value());
EXPECT_EQ("hello", a.value()); EXPECT_EQ("hello", a.value());
EXPECT_EQ("bye", b.value()); EXPECT_EQ("bye", b.value());
} }
...@@ -620,7 +620,7 @@ TEST(Optional, MakeOptional) { ...@@ -620,7 +620,7 @@ TEST(Optional, MakeOptional) {
// const L-value version // const L-value version
const std::string s("abc"); const std::string s("abc");
auto optStr = folly::make_optional(s); auto optStr = folly::make_optional(s);
ASSERT_TRUE(optStr.hasValue()); ASSERT_TRUE(optStr.has_value());
EXPECT_EQ(*optStr, "abc"); EXPECT_EQ(*optStr, "abc");
*optStr = "cde"; *optStr = "cde";
EXPECT_EQ(s, "abc"); EXPECT_EQ(s, "abc");
...@@ -629,7 +629,7 @@ TEST(Optional, MakeOptional) { ...@@ -629,7 +629,7 @@ TEST(Optional, MakeOptional) {
// L-value version // L-value version
std::string s2("abc"); std::string s2("abc");
auto optStr2 = folly::make_optional(s2); auto optStr2 = folly::make_optional(s2);
ASSERT_TRUE(optStr2.hasValue()); ASSERT_TRUE(optStr2.has_value());
EXPECT_EQ(*optStr2, "abc"); EXPECT_EQ(*optStr2, "abc");
*optStr2 = "cde"; *optStr2 = "cde";
// it's vital to check that s2 wasn't clobbered // it's vital to check that s2 wasn't clobbered
...@@ -638,7 +638,7 @@ TEST(Optional, MakeOptional) { ...@@ -638,7 +638,7 @@ TEST(Optional, MakeOptional) {
// L-value reference version // L-value reference version
std::string& s3(s2); std::string& s3(s2);
auto optStr3 = folly::make_optional(s3); auto optStr3 = folly::make_optional(s3);
ASSERT_TRUE(optStr3.hasValue()); ASSERT_TRUE(optStr3.has_value());
EXPECT_EQ(*optStr3, "abc"); EXPECT_EQ(*optStr3, "abc");
*optStr3 = "cde"; *optStr3 = "cde";
EXPECT_EQ(s3, "abc"); EXPECT_EQ(s3, "abc");
...@@ -647,7 +647,7 @@ TEST(Optional, MakeOptional) { ...@@ -647,7 +647,7 @@ TEST(Optional, MakeOptional) {
unique_ptr<int> pInt(new int(3)); unique_ptr<int> pInt(new int(3));
auto optIntPtr = folly::make_optional(std::move(pInt)); auto optIntPtr = folly::make_optional(std::move(pInt));
EXPECT_TRUE(pInt.get() == nullptr); EXPECT_TRUE(pInt.get() == nullptr);
ASSERT_TRUE(optIntPtr.hasValue()); ASSERT_TRUE(optIntPtr.has_value());
EXPECT_EQ(**optIntPtr, 3); EXPECT_EQ(**optIntPtr, 3);
// variadic version // variadic version
...@@ -682,11 +682,11 @@ TEST(Optional, TestDisambiguationMakeOptionalVariants) { ...@@ -682,11 +682,11 @@ TEST(Optional, TestDisambiguationMakeOptionalVariants) {
TEST(Optional, SelfAssignment) { TEST(Optional, SelfAssignment) {
Optional<int> a = 42; Optional<int> a = 42;
a = static_cast<decltype(a)&>(a); // suppress self-assign warning a = static_cast<decltype(a)&>(a); // suppress self-assign warning
ASSERT_TRUE(a.hasValue() && a.value() == 42); ASSERT_TRUE(a.has_value() && a.value() == 42);
Optional<int> b = 23333333; Optional<int> b = 23333333;
b = static_cast<decltype(b)&&>(b); // suppress self-move warning b = static_cast<decltype(b)&&>(b); // suppress self-move warning
ASSERT_TRUE(b.hasValue() && b.value() == 23333333); ASSERT_TRUE(b.has_value() && b.value() == 23333333);
} }
namespace { namespace {
...@@ -696,7 +696,7 @@ class ContainsOptional { ...@@ -696,7 +696,7 @@ class ContainsOptional {
ContainsOptional() {} ContainsOptional() {}
explicit ContainsOptional(int x) : opt_(x) {} explicit ContainsOptional(int x) : opt_(x) {}
bool hasValue() const { bool hasValue() const {
return opt_.hasValue(); return opt_.has_value();
} }
int value() const { int value() const {
return opt_.value(); return opt_.value();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment