Fixed usage of std::optional value_or:

value = value.value_or(...)
This commit is contained in:
Gerhard Hoffmann 2024-01-30 14:05:40 +01:00
parent c799c24658
commit f46adac56d

View File

@ -499,7 +499,7 @@ Configuration::getDailyTicketsForAllKeys() const {
} }
if (tickets.size() > 0) { if (tickets.size() > 0) {
value.value_or(tickets); value = value.value_or(tickets);
} }
return value; return value;
@ -510,18 +510,14 @@ Configuration::getDailyTicketsForKey(int key) const {
QVector<ATBDailyTicket> tickets; QVector<ATBDailyTicket> tickets;
std::optional<QVector<ATBDailyTicket>> value; std::optional<QVector<ATBDailyTicket>> value;
std::pair< tickets.clear();
std::multimap<int, ATBDailyTicket>::const_iterator,
std::multimap<int, ATBDailyTicket>::const_iterator
> p = this->DailyTicket.equal_range(key);
for (std::multimap<int, ATBDailyTicket>::const_iterator it = p.first; for (auto[it, rangeEnd] = this->DailyTicket.equal_range(key); it != rangeEnd; ++it) {
it != p.second; ++it) {
tickets.append(it->second); tickets.append(it->second);
} }
if (tickets.size() > 0) { if (tickets.size() > 0) {
value.value_or(tickets); value = value.value_or(tickets);
} }
return value; return value;
@ -538,7 +534,7 @@ Configuration::getPaymentRateForAllKeys() const {
} }
if (paymentRates.size() > 0) { if (paymentRates.size() > 0) {
value.value_or(paymentRates); value = value.value_or(paymentRates);
} }
return value; return value;
@ -550,18 +546,14 @@ Configuration::getPaymentRateForKey(int key) const {
QVector<ATBPaymentRate> paymentRate; QVector<ATBPaymentRate> paymentRate;
std::optional<QVector<ATBPaymentRate>> value; std::optional<QVector<ATBPaymentRate>> value;
std::pair< paymentRate.clear();
std::multimap<int, ATBPaymentRate>::const_iterator,
std::multimap<int, ATBPaymentRate>::const_iterator
> p = this->PaymentRate.equal_range(key);
for (std::multimap<int, ATBPaymentRate>::const_iterator it = p.first; for (auto[it, rangeEnd] = this->PaymentRate.equal_range(key); it != rangeEnd; ++it) {
it != p.second; ++it) {
paymentRate.append(it->second); paymentRate.append(it->second);
} }
if (paymentRate.size() > 0) { if (paymentRate.size() > 0) {
value.value_or(paymentRate); value = value.value_or(paymentRate);
} }
return value; return value;
@ -590,7 +582,7 @@ Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
ATBWeekDaysWorktime const &wt = it->second; ATBWeekDaysWorktime const &wt = it->second;
if (QTime::fromString(wt.pwd_time_from.c_str(), Qt::ISODate) >= time if (QTime::fromString(wt.pwd_time_from.c_str(), Qt::ISODate) >= time
&& QTime::fromString(wt.pwd_time_to.c_str(), Qt::ISODate) < time) { && QTime::fromString(wt.pwd_time_to.c_str(), Qt::ISODate) < time) {
value.value_or(wt); value = value.value_or(wt);
} }
} }