Don't use std::optional::value() because f u macos

This replaces all use of std::optional's `opt.value()` with `*opt`
because macOS is great and the ghost of Steve Jobs says that actually
supporting std::optional's value() method is not for chumps before macOS
10.14.  So don't use it because Apple is great.

Pretty much all of our use of it actually is done better with operator*
anyway (since operator* doesn't do a check that the optional has a
value).

Also replaced *most* of the `has_value()` calls with direct bool
context, except for one in the config section which looked really
confusing at a glance without a has_value().
pull/1282/head
Jason Rhinelander 4 years ago
parent 7f9160bb6e
commit ebd2142114

@ -6,7 +6,7 @@ set(std_optional_code [[
int main() { int main() {
std::optional<int> maybe; std::optional<int> maybe;
maybe = 1; maybe = 1;
return maybe.value() == 1; return *maybe == 1;
} }
]]) ]])

@ -192,9 +192,9 @@ namespace llarp
if (arg.empty()) if (arg.empty())
{ {
const auto maybe = llarp::FindFreeRange(); const auto maybe = llarp::FindFreeRange();
if (not maybe.has_value()) if (not maybe)
throw std::invalid_argument("cannot determine free ip range"); throw std::invalid_argument("cannot determine free ip range");
arg = maybe.value(); arg = *maybe;
} }
m_ifaddr = arg; m_ifaddr = arg;
}); });
@ -203,9 +203,9 @@ namespace llarp
if (arg.empty()) if (arg.empty())
{ {
const auto maybe = llarp::FindFreeTun(); const auto maybe = llarp::FindFreeTun();
if (not maybe.has_value()) if (not maybe)
throw std::invalid_argument("cannot determine free interface name"); throw std::invalid_argument("cannot determine free interface name");
arg = maybe.value(); arg = *maybe;
} }
m_ifname = arg; m_ifname = arg;
}); });
@ -228,8 +228,7 @@ namespace llarp
(void)params; (void)params;
auto parseDNSAddr = [](auto arg) { auto parseDNSAddr = [](auto arg) {
IpAddress addr{arg}; IpAddress addr{arg};
const auto maybePort = addr.getPort(); if (not addr.getPort())
if (not maybePort.has_value())
addr.setPort(53); addr.setPort(53);
return addr; return addr;
}; };
@ -399,10 +398,10 @@ namespace llarp
conf.defineOption<std::string>( conf.defineOption<std::string>(
"logging", "level", false, DefaultLogLevel, [this](std::string arg) { "logging", "level", false, DefaultLogLevel, [this](std::string arg) {
std::optional<LogLevel> level = LogLevelFromString(arg); std::optional<LogLevel> level = LogLevelFromString(arg);
if (not level.has_value()) if (not level)
throw std::invalid_argument(stringify("invalid log level value: ", arg)); throw std::invalid_argument(stringify("invalid log level value: ", arg));
m_logLevel = level.value(); m_logLevel = *level;
}); });
conf.defineOption<std::string>( conf.defineOption<std::string>(
@ -553,13 +552,13 @@ namespace llarp
// open a filestream // open a filestream
auto stream = llarp::util::OpenFileStream<std::ofstream>(confFile.c_str(), std::ios::binary); auto stream = llarp::util::OpenFileStream<std::ofstream>(confFile.c_str(), std::ios::binary);
if (not stream.has_value() or not stream.value().is_open()) if (not stream or not stream->is_open())
throw std::runtime_error(stringify("Failed to open file ", confFile, " for writing")); throw std::runtime_error(stringify("Failed to open file ", confFile, " for writing"));
llarp::LogInfo("confStr: ", confStr); llarp::LogInfo("confStr: ", confStr);
stream.value() << confStr; *stream << confStr;
stream.value().flush(); stream->flush();
llarp::LogInfo("Generated new config ", confFile); llarp::LogInfo("Generated new config ", confFile);
} }

@ -156,8 +156,8 @@ namespace llarp
defaultValueAsString() override defaultValueAsString() override
{ {
std::ostringstream oss; std::ostringstream oss;
if (defaultValue.has_value()) if (defaultValue)
oss << defaultValue.value(); oss << *defaultValue;
return oss.str(); return oss.str();
} }
@ -192,8 +192,8 @@ namespace llarp
std::ostringstream oss; std::ostringstream oss;
if (parsedValues.size() > 0) if (parsedValues.size() > 0)
oss << parsedValues[0]; oss << parsedValues[0];
else if (useDefault and defaultValue.has_value()) else if (useDefault and defaultValue)
oss << defaultValue.value(); oss << *defaultValue;
return oss.str(); return oss.str();
} }
@ -232,13 +232,13 @@ namespace llarp
else else
{ {
auto maybe = getValue(); auto maybe = getValue();
if (maybe.has_value()) if (maybe)
{ {
acceptor(maybe.value()); acceptor(*maybe);
} }
else else
{ {
assert(not defaultValue.has_value()); // maybe should have a value if defaultValue does assert(not defaultValue); // maybe should have a value if defaultValue does
} }
} }
} }

@ -29,7 +29,7 @@ namespace llarp
bool bool
Context::Configure(bool isRelay, std::optional<fs::path> dataDir) Context::Configure(bool isRelay, std::optional<fs::path> dataDir)
{ {
fs::path defaultDataDir = dataDir.has_value() ? dataDir.value() : GetDefaultDataDir(); fs::path defaultDataDir = dataDir ? *dataDir : GetDefaultDataDir();
if (configfile.size()) if (configfile.size())
{ {

@ -101,7 +101,7 @@ namespace llarp
auto optional_f = llarp::util::OpenFileStream<std::ofstream>(fpath, std::ios::binary); auto optional_f = llarp::util::OpenFileStream<std::ofstream>(fpath, std::ios::binary);
if (!optional_f) if (!optional_f)
return false; return false;
auto& f = optional_f.value(); auto& f = *optional_f;
if (!f.is_open()) if (!f.is_open())
return false; return false;
f.write((char*)buf.base, buf.cur - buf.base); f.write((char*)buf.base, buf.cur - buf.base);
@ -115,7 +115,7 @@ namespace llarp
auto optional = util::OpenFileStream<std::ifstream>(fpath, std::ios::binary | std::ios::in); auto optional = util::OpenFileStream<std::ifstream>(fpath, std::ios::binary | std::ios::in);
if (!optional) if (!optional)
return false; return false;
auto& f = optional.value(); auto& f = *optional;
f.seekg(0, std::ios::end); f.seekg(0, std::ios::end);
const size_t sz = f.tellg(); const size_t sz = f.tellg();
f.seekg(0, std::ios::beg); f.seekg(0, std::ios::beg);

@ -122,9 +122,9 @@ namespace llarp
{ {
// we should have this value if introset was propagated properly // we should have this value if introset was propagated properly
const auto maybe = dht.GetIntroSetByLocation(location); const auto maybe = dht.GetIntroSetByLocation(location);
if (maybe.has_value()) if (maybe)
{ {
replies.emplace_back(new GotIntroMessage({maybe.value()}, txID)); replies.emplace_back(new GotIntroMessage({*maybe}, txID));
} }
else else
{ {

@ -86,7 +86,7 @@ namespace llarp
} }
if (key == "K") if (key == "K")
{ {
if (closer.has_value()) // duplicate key? if (closer) // duplicate key?
return false; return false;
dht::Key_t K; dht::Key_t K;
if (not K.BDecode(buf)) if (not K.BDecode(buf))
@ -111,9 +111,9 @@ namespace llarp
return false; return false;
if (!BEncodeWriteDictList("I", found, buf)) if (!BEncodeWriteDictList("I", found, buf))
return false; return false;
if (closer.has_value()) if (closer)
{ {
if (!BEncodeWriteDictEntry("K", closer.value(), buf)) if (!BEncodeWriteDictEntry("K", *closer, buf))
return false; return false;
} }
if (!BEncodeWriteDictInt("T", txid, buf)) if (!BEncodeWriteDictInt("T", txid, buf))

@ -15,9 +15,9 @@ namespace llarp
llarp::LogWarn("got invalid introset from tag lookup"); llarp::LogWarn("got invalid introset from tag lookup");
return false; return false;
} }
if (not introset.topic.has_value()) if (not introset.topic)
return false; return false;
if (introset.topic.value() != target) if (*introset.topic != target)
{ {
llarp::LogWarn("got introset with mismatched topic in tag lookup"); llarp::LogWarn("got introset with mismatched topic in tag lookup");
return false; return false;

@ -125,10 +125,9 @@ namespace llarp
} }
else else
{ {
const auto maybe = GetIFAddr(ifname, af); if (const auto maybe = GetIFAddr(ifname, af))
if (maybe.has_value())
{ {
m_ourAddr = maybe.value(); m_ourAddr = *maybe;
} }
else else
{ {

@ -261,14 +261,14 @@ namespace llarp
return; return;
} }
if (self->fromAddr.has_value()) if (self->fromAddr)
{ {
// only do ip limiting from non service nodes // only do ip limiting from non service nodes
#ifndef LOKINET_HIVE #ifndef LOKINET_HIVE
if (self->context->CheckPathLimitHitByIP(self->fromAddr.value())) if (self->context->CheckPathLimitHitByIP(*self->fromAddr))
{ {
// we hit a limit so tell it to slow tf down // we hit a limit so tell it to slow tf down
llarp::LogError("client path build hit limit ", self->fromAddr.value()); llarp::LogError("client path build hit limit ", *self->fromAddr);
OnForwardLRCMResult( OnForwardLRCMResult(
self->context->Router(), self->context->Router(),
self->hop->info.rxID, self->hop->info.rxID,

@ -164,11 +164,7 @@ namespace llarp
const sockaddr_in6* addr6 = addr; const sockaddr_in6* addr6 = addr;
memcpy(ip.s6_addr, addr6->sin6_addr.s6_addr, sizeof(ip.s6_addr)); memcpy(ip.s6_addr, addr6->sin6_addr.s6_addr, sizeof(ip.s6_addr));
auto maybePort = address.getPort(); port = address.getPort().value_or(0);
if (maybePort)
port = maybePort.value();
else
port = 0;
} }
std::ostream& std::ostream&

@ -94,7 +94,7 @@ namespace llarp
{ {
SockAddr addr(m_ipAddress); SockAddr addr(m_ipAddress);
if (m_port) if (m_port)
addr.setPort(m_port.value()); addr.setPort(*m_port);
return addr; return addr;
} }

@ -259,7 +259,7 @@ llarp_nodedb::SaveAll()
filepath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); filepath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
if (!optional_ofs) if (!optional_ofs)
continue; continue;
auto& ofs = optional_ofs.value(); auto& ofs = *optional_ofs;
ofs.write((char*)buf.base, buf.sz); ofs.write((char*)buf.base, buf.sz);
ofs.flush(); ofs.flush();
ofs.close(); ofs.close();

@ -192,12 +192,12 @@ namespace llarp
} }
else else
{ {
if (failedAt.has_value()) if (failedAt)
{ {
r->NotifyRouterEvent<tooling::PathBuildRejectedEvent>( r->NotifyRouterEvent<tooling::PathBuildRejectedEvent>(
Endpoint(), RXID(), failedAt.value()); Endpoint(), RXID(), *failedAt);
LogWarn(Name(), " build failed at ", failedAt.value()); LogWarn(Name(), " build failed at ", *failedAt);
r->routerProfiling().MarkHopFail(failedAt.value()); r->routerProfiling().MarkHopFail(*failedAt);
} }
else else
r->routerProfiling().MarkPathFail(this); r->routerProfiling().MarkPathFail(this);

@ -125,9 +125,9 @@ namespace llarp
do do
{ {
auto maybe = self->m_DownstreamGather.tryPopFront(); auto maybe = self->m_DownstreamGather.tryPopFront();
if (not maybe.has_value()) if (not maybe)
break; break;
msgs.emplace_back(maybe.value()); msgs.emplace_back(*maybe);
} while (true); } while (true);
self->HandleAllDownstream(std::move(msgs), r); self->HandleAllDownstream(std::move(msgs), r);
}; };
@ -167,9 +167,9 @@ namespace llarp
do do
{ {
auto maybe = self->m_UpstreamGather.tryPopFront(); auto maybe = self->m_UpstreamGather.tryPopFront();
if (not maybe.has_value()) if (not maybe)
break; break;
msgs.emplace_back(maybe.value()); msgs.emplace_back(*maybe);
} while (true); } while (true);
self->HandleAllUpstream(std::move(msgs), r); self->HandleAllUpstream(std::move(msgs), r);
}; };

@ -230,7 +230,7 @@ namespace llarp
auto optional_f = util::OpenFileStream<std::ofstream>(fpath, std::ios::binary); auto optional_f = util::OpenFileStream<std::ofstream>(fpath, std::ios::binary);
if (!optional_f) if (!optional_f)
return false; return false;
auto& f = optional_f.value(); auto& f = *optional_f;
if (f.is_open()) if (f.is_open())
{ {
f.write((char*)buf.base, buf.sz); f.write((char*)buf.base, buf.sz);

@ -548,13 +548,10 @@ namespace llarp
} }
// Network config // Network config
if (conf->network.m_enableProfiling.has_value()) if (conf->network.m_enableProfiling.has_value() and not *conf->network.m_enableProfiling)
{ {
if (not conf->network.m_enableProfiling.value()) routerProfiling().Disable();
{ LogWarn("router profiling explicitly disabled");
routerProfiling().Disable();
LogWarn("router profiling explicitly disabled");
}
} }
if (!conf->network.m_routerProfilesFile.empty()) if (!conf->network.m_routerProfilesFile.empty())

@ -125,9 +125,9 @@ namespace llarp
if (!enckey.BEncode(buf)) if (!enckey.BEncode(buf))
return false; return false;
// write router version if present // write router version if present
if (routerVersion.has_value()) if (routerVersion)
{ {
if (not BEncodeWriteDictEntry("r", routerVersion.value(), buf)) if (not BEncodeWriteDictEntry("r", *routerVersion, buf))
return false; return false;
} }
/* write last updated */ /* write last updated */
@ -180,7 +180,7 @@ namespace llarp
{ {
obj["nickname"] = Nick(); obj["nickname"] = Nick();
} }
if (routerVersion.has_value()) if (routerVersion)
{ {
obj["routerVersion"] = routerVersion->ToString(); obj["routerVersion"] = routerVersion->ToString();
} }
@ -246,7 +246,7 @@ namespace llarp
bool bool
RouterContact::IsPublicRouter() const RouterContact::IsPublicRouter() const
{ {
if (not routerVersion.has_value()) if (not routerVersion)
return false; return false;
return !addrs.empty(); return !addrs.empty();
} }
@ -390,17 +390,16 @@ namespace llarp
buf.sz = buf.cur - buf.base; buf.sz = buf.cur - buf.base;
buf.cur = buf.base; buf.cur = buf.base;
const fs::path fpath = std::string(fname); /* */ const fs::path fpath = std::string(fname); /* */
auto optional_f = llarp::util::OpenFileStream<std::ofstream>(fpath, std::ios::binary); auto f = llarp::util::OpenFileStream<std::ofstream>(fpath, std::ios::binary);
if (!optional_f) if (!f)
{ {
return false; return false;
} }
auto& f = optional_f.value(); if (!f->is_open())
if (!f.is_open())
{ {
return false; return false;
} }
f.write((char*)buf.base, buf.sz); f->write((char*)buf.base, buf.sz);
return true; return true;
} }

@ -106,12 +106,12 @@ namespace llarp
return; return;
} }
auto maybe = m_Identity.EncryptAndSignIntroSet(introSet(), now); auto maybe = m_Identity.EncryptAndSignIntroSet(introSet(), now);
if (not maybe.has_value()) if (not maybe)
{ {
LogWarn("failed to generate introset for endpoint ", Name()); LogWarn("failed to generate introset for endpoint ", Name());
return; return;
} }
if (PublishIntroSet(maybe.value(), Router())) if (PublishIntroSet(*maybe, Router()))
{ {
LogInfo("(re)publishing introset for endpoint ", Name()); LogInfo("(re)publishing introset for endpoint ", Name());
} }
@ -798,9 +798,9 @@ namespace llarp
do do
{ {
auto maybe = m_RecvQueue.tryPopFront(); auto maybe = m_RecvQueue.tryPopFront();
if (not maybe.has_value()) if (not maybe)
return; return;
auto ev = std::move(maybe.value()); auto ev = std::move(*maybe);
ProtocolMessage::ProcessAsync(ev.fromPath, ev.pathid, ev.msg); ProtocolMessage::ProcessAsync(ev.fromPath, ev.pathid, ev.msg);
} while (true); } while (true);
} }
@ -928,7 +928,7 @@ namespace llarp
const auto now = Router()->Now(); const auto now = Router()->Now();
auto& fails = m_state->m_ServiceLookupFails; auto& fails = m_state->m_ServiceLookupFails;
auto& lookups = m_state->m_PendingServiceLookups; auto& lookups = m_state->m_PendingServiceLookups;
if (not introset.has_value() || introset->IsExpired(now)) if (not introset or introset->IsExpired(now))
{ {
LogError(Name(), " failed to lookup ", addr.ToString(), " from ", endpoint); LogError(Name(), " failed to lookup ", addr.ToString(), " from ", endpoint);
fails[endpoint] = fails[endpoint] + 1; fails[endpoint] = fails[endpoint] + 1;
@ -947,7 +947,7 @@ namespace llarp
if (m_state->m_RemoteSessions.count(addr) > 0) if (m_state->m_RemoteSessions.count(addr) > 0)
return true; return true;
PutNewOutboundContext(introset.value()); PutNewOutboundContext(*introset);
return true; return true;
} }

@ -38,8 +38,8 @@ namespace llarp
selected = introset; selected = introset;
} }
const auto maybe = selected.MaybeDecrypt(rootkey); const auto maybe = selected.MaybeDecrypt(rootkey);
if (maybe.has_value()) if (maybe)
found = maybe.value(); found = *maybe;
} }
return handle(remote, found, endpoint); return handle(remote, found, endpoint);
} }

@ -118,7 +118,7 @@ namespace llarp
auto optional_f = util::OpenFileStream<std::ofstream>(fname, std::ios::binary); auto optional_f = util::OpenFileStream<std::ofstream>(fname, std::ios::binary);
if (!optional_f) if (!optional_f)
return false; return false;
auto& f = optional_f.value(); auto& f = *optional_f;
if (!f.is_open()) if (!f.is_open())
return false; return false;
f.write((char*)buf.cur, buf.sz); f.write((char*)buf.cur, buf.sz);
@ -143,7 +143,7 @@ namespace llarp
if (!bencode_decode_dict(*this, &buf)) if (!bencode_decode_dict(*this, &buf))
return false; return false;
ServiceInfo::OptNonce van; std::optional<VanityNonce> van;
if (!vanity.IsZero()) if (!vanity.IsZero())
van = vanity; van = vanity;
// update pubkeys // update pubkeys

@ -20,13 +20,13 @@ namespace llarp
} }
bool bool
ServiceInfo::Update(const byte_t* sign, const byte_t* enc, const OptNonce& nonce) ServiceInfo::Update(const byte_t* sign, const byte_t* enc, const std::optional<VanityNonce>& nonce)
{ {
signkey = sign; signkey = sign;
enckey = enc; enckey = enc;
if (nonce) if (nonce)
{ {
vanity = nonce.value(); vanity = *nonce;
} }
return UpdateAddr(); return UpdateAddr();
} }

@ -23,8 +23,6 @@ namespace llarp
VanityNonce vanity; VanityNonce vanity;
uint64_t version = LLARP_PROTO_VERSION; uint64_t version = LLARP_PROTO_VERSION;
using OptNonce = std::optional<VanityNonce>;
void void
RandomizeVanity() RandomizeVanity()
{ {
@ -45,7 +43,7 @@ namespace llarp
} }
bool bool
Update(const byte_t* sign, const byte_t* enc, const OptNonce& nonce = OptNonce()); Update(const byte_t* sign, const byte_t* enc, const std::optional<VanityNonce>& nonce = {});
bool bool
operator==(const ServiceInfo& other) const operator==(const ServiceInfo& other) const

@ -279,13 +279,13 @@ namespace llarp
{ {
if (intro.expiresAt > now && intro.expiresAt - now > path::default_lifetime) if (intro.expiresAt > now && intro.expiresAt - now > path::default_lifetime)
{ {
if (W && intro.expiresAt - W->extendedLifetime > path::default_lifetime) if (!W)
{ {
LogWarn("intro has too high expire time");
return false; return false;
} }
if (!W.has_value()) if (intro.expiresAt - W->extendedLifetime > path::default_lifetime)
{ {
LogWarn("intro has too high expire time");
return false; return false;
} }
} }
@ -329,7 +329,7 @@ namespace llarp
printer.printAttribute("T", T.count()); printer.printAttribute("T", T.count());
if (W) if (W)
{ {
printer.printAttribute("W", W.value()); printer.printAttribute("W", *W);
} }
else else
{ {

@ -90,11 +90,11 @@ namespace llarp
if (markedBad) if (markedBad)
return true; return true;
updatingIntroSet = false; updatingIntroSet = false;
if (foundIntro.has_value()) if (foundIntro)
{ {
if (foundIntro->T == 0s) if (foundIntro->T == 0s)
{ {
LogWarn(Name(), " got introset with zero timestamp: ", foundIntro.value()); LogWarn(Name(), " got introset with zero timestamp: ", *foundIntro);
return true; return true;
} }
if (currentIntroSet.T > foundIntro->T) if (currentIntroSet.T > foundIntro->T)
@ -109,7 +109,7 @@ namespace llarp
LogError("got expired introset from lookup from ", endpoint); LogError("got expired introset from lookup from ", endpoint);
return true; return true;
} }
currentIntroSet = foundIntro.value(); currentIntroSet = *foundIntro;
ShiftIntroduction(false); ShiftIntroduction(false);
} }
else else

@ -46,9 +46,9 @@ namespace llarp
do do
{ {
auto maybe = m_SendQueue.tryPopFront(); auto maybe = m_SendQueue.tryPopFront();
if (not maybe.has_value()) if (not maybe)
break; break;
auto& item = maybe.value(); auto& item = *maybe;
if (item.second->SendRoutingMessage(*item.first, r)) if (item.second->SendRoutingMessage(*item.first, r))
{ {
lastGoodSend = r->Now(); lastGoodSend = r->Now();

@ -357,13 +357,10 @@ namespace llarp
buf.sz = buf.cur - buf.base; buf.sz = buf.cur - buf.base;
{ {
const fs::path path = std::string(fpath); const fs::path path = std::string(fpath);
auto optional_f = llarp::util::OpenFileStream<std::ofstream>(path, std::ios::binary); auto f = llarp::util::OpenFileStream<std::ofstream>(path, std::ios::binary);
if (!optional_f) if (not f or not f->is_open())
return false; return false;
auto& f = optional_f.value(); f->write((char*)buf.base, buf.sz);
if (!f.is_open())
return false;
f.write((char*)buf.base, buf.sz);
} }
return true; return true;
} }

@ -14,10 +14,9 @@ namespace llarp
do do
{ {
auto maybe_line = lines->tryPopFront(); auto maybe_line = lines->tryPopFront();
if (not maybe_line.has_value()) if (not maybe_line)
break; break;
const auto& line = maybe_line.value(); if (fprintf(f, "%s\n", maybe_line->c_str()) >= 0)
if (fprintf(f, "%s\n", line.c_str()) >= 0)
wrote_stuff = true; wrote_stuff = true;
} while (true); } while (true);
@ -43,7 +42,7 @@ namespace llarp
do do
{ {
auto line = m_Lines.tryPopFront(); auto line = m_Lines.tryPopFront();
if (not line.has_value()) if (not line)
break; break;
} while (true); } while (true);
fflush(m_File); fflush(m_File);

@ -13,8 +13,8 @@ namespace llarp
std::promise<ID_t> result; std::promise<ID_t> result;
// queue setting id and try to get the result back // queue setting id and try to get the result back
llarp_threadpool_queue_job(m_Thread, [&]() { llarp_threadpool_queue_job(m_Thread, [&]() {
m_ID.emplace(std::this_thread::get_id()); m_ID = std::this_thread::get_id();
result.set_value(m_ID.value()); result.set_value(*m_ID);
}); });
// get the result back // get the result back
ID_t spawned = result.get_future().get(); ID_t spawned = result.get_future().get();
@ -129,7 +129,7 @@ namespace llarp
bool bool
Logic::can_flush() const Logic::can_flush() const
{ {
return m_ID.value() == std::this_thread::get_id(); return *m_ID == std::this_thread::get_id();
} }
void void

@ -27,9 +27,9 @@ namespace llarp
{ {
auto functor = m_queue.tryPopFront(); auto functor = m_queue.tryPopFront();
if (functor.has_value()) if (functor)
{ {
functor.value()(); (*functor)();
} }
else else
{ {
@ -57,7 +57,7 @@ namespace llarp
return; return;
} }
functor.value()(); (*functor)();
} }
} }

@ -51,13 +51,13 @@ namespace llarp
{ {
if (!m_id) if (!m_id)
{ {
m_id.emplace(std::this_thread::get_id()); m_id = std::this_thread::get_id();
} }
else if (m_id.value() != std::this_thread::get_id()) else if (*m_id != std::this_thread::get_id())
{ {
std::cerr << "NullMutex " << this << " was used across threads: locked by " std::cerr << "NullMutex " << this << " was used across threads: locked by "
<< std::this_thread::get_id() << " and was previously locked by " << std::this_thread::get_id() << " and was previously locked by "
<< m_id.value() << "\n"; << *m_id << "\n";
// if you're encountering this abort() call, you may have discovered a // if you're encountering this abort() call, you may have discovered a
// case where a NullMutex should be reverted to a "real mutex" // case where a NullMutex should be reverted to a "real mutex"
std::abort(); std::abort();

@ -392,14 +392,14 @@ TEST_CASE("ConfigDefinition truthy/falsy bool values", "[config]")
// defaults to false // defaults to false
auto maybe = def.getValue(); auto maybe = def.getValue();
CHECK(maybe.has_value()); REQUIRE(maybe);
CHECK(maybe.value() == false); CHECK(*maybe == false);
// val should result in true // val should result in true
CHECK_NOTHROW(def.parseValue(val)); CHECK_NOTHROW(def.parseValue(val));
maybe = def.getValue(); maybe = def.getValue();
CHECK(maybe.has_value()); REQUIRE(maybe);
CHECK(maybe.value() == true); CHECK(*maybe);
} }
// falsy values // falsy values
@ -409,14 +409,14 @@ TEST_CASE("ConfigDefinition truthy/falsy bool values", "[config]")
// defaults to true // defaults to true
auto maybe = def.getValue(); auto maybe = def.getValue();
CHECK(maybe.has_value()); REQUIRE(maybe);
CHECK(maybe.value() == true); CHECK(maybe == true);
// val should result in false // val should result in false
CHECK_NOTHROW(def.parseValue(val)); CHECK_NOTHROW(def.parseValue(val));
maybe = def.getValue(); maybe = def.getValue();
CHECK(maybe.has_value()); REQUIRE(maybe);
CHECK(maybe.value() == false); CHECK(maybe == false);
} }
// illegal values // illegal values

@ -577,7 +577,7 @@ TEST(TestQueue, moveIt)
std::optional< MoveTester > optPopped = queue.tryPopFront(); std::optional< MoveTester > optPopped = queue.tryPopFront();
ASSERT_TRUE(optPopped.has_value()); ASSERT_TRUE(optPopped);
// Moved twice here to construct the optional. // Moved twice here to construct the optional.
ASSERT_EQ(6u, counter); ASSERT_EQ(6u, counter);

@ -258,8 +258,8 @@ TEST(TestQueueManager, SimpleUsage)
auto result = queue.tryPopFront(); auto result = queue.tryPopFront();
ASSERT_TRUE(result.has_value()); ASSERT_TRUE(result);
ASSERT_EQ(1, result.value()); ASSERT_EQ(1, *result);
} }
class BasicFunctionality : public ::testing::TestWithParam< uint32_t > class BasicFunctionality : public ::testing::TestWithParam< uint32_t >

Loading…
Cancel
Save