2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Simplified ranges::find_if with ranges::any_of and ranges::none_of.

This commit is contained in:
23rd
2020-05-18 22:33:14 +03:00
committed by John Preston
parent 5f238a71f9
commit e318a7d65f
33 changed files with 71 additions and 105 deletions

View File

@@ -145,8 +145,8 @@ void ChatData::refreshBotStatus() {
if (participants.empty()) {
botStatus = 0;
} else {
const auto bot = ranges::find_if(participants, &UserData::isBot);
botStatus = (bot == end(participants)) ? -1 : 2;
const auto bot = ranges::none_of(participants, &UserData::isBot);
botStatus = bot ? -1 : 2;
}
}

View File

@@ -1482,7 +1482,7 @@ bool DocumentData::isAudioFile() const {
}
const auto left = _mimeString.midRef(prefix.size()).toString();
const auto types = { qstr("x-wav"), qstr("wav"), qstr("mp4") };
return ranges::find(types, left) != end(types);
return ranges::contains(types, left);
}
bool DocumentData::isSharedMediaMusic() const {

View File

@@ -548,10 +548,9 @@ bool Histories::postponeHistoryRequest(const State &state) const {
}
bool Histories::postponeEntryRequest(const State &state) const {
const auto i = ranges::find_if(state.sent, [](const auto &pair) {
return ranges::any_of(state.sent, [](const auto &pair) {
return pair.second.type != RequestType::History;
});
return (i != end(state.sent));
}
void Histories::deleteMessages(

View File

@@ -416,7 +416,7 @@ QString PeerData::computeUnavailableReason() const {
auto &&filtered = ranges::view::all(
list
) | ranges::view::filter([&](const Data::UnavailableReason &reason) {
return ranges::find(skip, reason.reason) == end(skip);
return !ranges::contains(skip, reason.reason);
});
const auto first = filtered.begin();
return (first != filtered.end()) ? first->text : QString();

View File

@@ -236,7 +236,7 @@ PollData::Flags PollData::flags() const {
}
bool PollData::voted() const {
return ranges::find(answers, true, &PollAnswer::chosen) != end(answers);
return ranges::contains(answers, true, &PollAnswer::chosen);
}
bool PollData::closed() const {

View File

@@ -3822,10 +3822,7 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
_wallpapers.push_back(*parsed);
}
}
const auto defaultFound = ranges::find_if(
_wallpapers,
Data::IsDefaultWallPaper);
if (defaultFound == end(_wallpapers)) {
if (ranges::none_of(_wallpapers, Data::IsDefaultWallPaper)) {
_wallpapers.push_back(Data::DefaultWallPaper());
_wallpapers.back().setLocalImageAsThumbnail(std::make_shared<Image>(
u":/gui/arg/bg.jpg"_q));

View File

@@ -51,11 +51,11 @@ std::optional<QColor> MaybeColorFromSerialized(quint32 serialized) {
std::optional<QColor> ColorFromString(const QString &string) {
if (string.size() != 6) {
return {};
} else if (ranges::find_if(string, [](QChar ch) {
} else if (ranges::any_of(string, [](QChar ch) {
return (ch < 'a' || ch > 'f')
&& (ch < 'A' || ch > 'F')
&& (ch < '0' || ch > '9');
}) != string.end()) {
})) {
return {};
}
const auto component = [](const QString &text, int index) {