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:
@@ -172,8 +172,7 @@ void ShowAddParticipantsError(
|
||||
return;
|
||||
}
|
||||
}
|
||||
const auto bot = ranges::find_if(users, &UserData::isBot);
|
||||
const auto hasBot = (bot != end(users));
|
||||
const auto hasBot = ranges::any_of(users, &UserData::isBot);
|
||||
const auto text = [&] {
|
||||
if (error == qstr("USER_BOT")) {
|
||||
return tr::lng_cant_invite_bot_to_channel(tr::now);
|
||||
|
@@ -172,26 +172,26 @@ void AutoDownloadBox::setupContent() {
|
||||
}) | ranges::view::transform([](Pair pair) {
|
||||
return pair.first;
|
||||
});
|
||||
const auto less = ranges::find_if(*autoPlayValues, [&](Pair pair) {
|
||||
const auto less = ranges::any_of(*autoPlayValues, [&](Pair pair) {
|
||||
const auto [type, enabled] = pair;
|
||||
const auto value = enabled ? limitByType(type) : 0;
|
||||
return value < settings->bytesLimit(_source, type);
|
||||
}) != end(*autoPlayValues);
|
||||
});
|
||||
const auto allowMoreTypes = base::flat_set<Type>(
|
||||
allowMore.begin(),
|
||||
allowMore.end());
|
||||
|
||||
const auto changed = ranges::find_if(values, [&](Pair pair) {
|
||||
const auto changed = ranges::any_of(values, [&](Pair pair) {
|
||||
const auto [type, enabled] = pair;
|
||||
const auto value = enabled ? limitByType(type) : 0;
|
||||
return value != settings->bytesLimit(_source, type);
|
||||
}) != end(values);
|
||||
});
|
||||
|
||||
const auto &kHidden = kStreamedTypes;
|
||||
const auto hiddenChanged = ranges::find_if(kHidden, [&](Type type) {
|
||||
const auto hiddenChanged = ranges::any_of(kHidden, [&](Type type) {
|
||||
const auto now = settings->bytesLimit(_source, type);
|
||||
return (now > 0) && (now != limitByType(type));
|
||||
}) != end(kHidden);
|
||||
});
|
||||
|
||||
if (changed) {
|
||||
for (const auto [type, enabled] : values) {
|
||||
@@ -216,8 +216,7 @@ void AutoDownloadBox::setupContent() {
|
||||
if (allowMoreTypes.contains(Type::Photo)) {
|
||||
_session->data().photoLoadSettingsChanged();
|
||||
}
|
||||
if (ranges::find_if(allowMoreTypes, _1 != Type::Photo)
|
||||
!= allowMoreTypes.end()) {
|
||||
if (ranges::any_of(allowMoreTypes, _1 != Type::Photo)) {
|
||||
_session->data().documentLoadSettingsChanged();
|
||||
}
|
||||
if (less) {
|
||||
|
@@ -271,14 +271,14 @@ bool ServiceCheck::checkRippleStartPosition(QPoint position) const {
|
||||
if (slug.isEmpty() || slug.size() > kMaxWallPaperSlugLength) {
|
||||
return false;
|
||||
}
|
||||
return ranges::find_if(slug, [](QChar ch) {
|
||||
return ranges::none_of(slug, [](QChar ch) {
|
||||
return (ch != '.')
|
||||
&& (ch != '_')
|
||||
&& (ch != '-')
|
||||
&& (ch < '0' || ch > '9')
|
||||
&& (ch < 'a' || ch > 'z')
|
||||
&& (ch < 'A' || ch > 'Z');
|
||||
}) == slug.end();
|
||||
});
|
||||
}
|
||||
|
||||
AdminLog::OwnedItem GenerateTextItem(
|
||||
|
@@ -678,10 +678,7 @@ auto DeleteMessagesBox::revokeText(not_null<PeerData*> peer) const
|
||||
const auto cannotRevoke = [&](HistoryItem *item) {
|
||||
return !item->canDeleteForEveryone(now);
|
||||
};
|
||||
const auto canRevokeAll = ranges::find_if(
|
||||
items,
|
||||
cannotRevoke
|
||||
) == end(items);
|
||||
const auto canRevokeAll = ranges::none_of(items, cannotRevoke);
|
||||
auto outgoing = items | ranges::view::filter(&HistoryItem::out);
|
||||
const auto canRevokeOutgoingCount = canRevokeAll
|
||||
? -1
|
||||
|
@@ -1028,7 +1028,7 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
||||
: QString());
|
||||
*box = Ui::show(Box<ConfirmBox>(text, tr::lng_sure_enable(tr::now), [=] {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
if (ranges::find(proxies, proxy) == end(proxies)) {
|
||||
if (!ranges::contains(proxies, proxy)) {
|
||||
proxies.push_back(proxy);
|
||||
}
|
||||
Core::App().setCurrentProxy(
|
||||
|
@@ -724,9 +724,8 @@ void Options::removeDestroyed(not_null<Option*> option) {
|
||||
void Options::validateState() {
|
||||
checkLastOption();
|
||||
_hasOptions = (ranges::count_if(_list, &Option::isGood) > 1);
|
||||
_isValid = _hasOptions
|
||||
&& (ranges::find_if(_list, &Option::isTooLong) == end(_list));
|
||||
_hasCorrect = ranges::find_if(_list, &Option::isCorrect) != end(_list);
|
||||
_isValid = _hasOptions && ranges::none_of(_list, &Option::isTooLong);
|
||||
_hasCorrect = ranges::any_of(_list, &Option::isCorrect);
|
||||
|
||||
const auto lastEmpty = !_list.empty() && _list.back()->isEmpty();
|
||||
_usedCount = _list.size() - (lastEmpty ? 1 : 0);
|
||||
|
@@ -485,12 +485,12 @@ void Controller::usernameChanged() {
|
||||
_checkUsernameTimer.cancel();
|
||||
return;
|
||||
}
|
||||
const auto bad = ranges::find_if(username, [](QChar ch) {
|
||||
const auto bad = ranges::any_of(username, [](QChar ch) {
|
||||
return (ch < 'A' || ch > 'Z')
|
||||
&& (ch < 'a' || ch > 'z')
|
||||
&& (ch < '0' || ch > '9')
|
||||
&& (ch != '_');
|
||||
}) != username.end();
|
||||
});
|
||||
if (bad) {
|
||||
showUsernameError(tr::lng_create_channel_link_bad_symbols());
|
||||
} else if (username.size() < kMinUsernameLength) {
|
||||
|
@@ -62,10 +62,7 @@ enum class ButtonType {
|
||||
};
|
||||
|
||||
inline bool CanAddUrls(const QList<QUrl> &urls) {
|
||||
return !urls.isEmpty() && ranges::find_if(
|
||||
urls,
|
||||
[](const QUrl &url) { return !url.isLocalFile(); }
|
||||
) == urls.end();
|
||||
return !urls.isEmpty() && ranges::all_of(urls, &QUrl::isLocalFile);
|
||||
}
|
||||
|
||||
inline bool IsFirstAlbumItem(const Storage::PreparedList &list) {
|
||||
|
Reference in New Issue
Block a user