From e318a7d65f731c211eb3b07ba8d77de4fd83b445 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 18 May 2020 22:33:14 +0300 Subject: [PATCH] Simplified ranges::find_if with ranges::any_of and ranges::none_of. --- Telegram/SourceFiles/api/api_updates.cpp | 4 +-- Telegram/SourceFiles/apiwrap.cpp | 4 +-- .../SourceFiles/boxes/add_contact_box.cpp | 3 +- .../SourceFiles/boxes/auto_download_box.cpp | 15 ++++---- .../boxes/background_preview_box.cpp | 4 +-- Telegram/SourceFiles/boxes/confirm_box.cpp | 5 +-- Telegram/SourceFiles/boxes/connection_box.cpp | 2 +- .../SourceFiles/boxes/create_poll_box.cpp | 5 ++- .../boxes/peers/edit_peer_type_box.cpp | 4 +-- Telegram/SourceFiles/boxes/send_files_box.cpp | 5 +-- .../chat_helpers/emoji_keywords.cpp | 2 +- .../chat_helpers/emoji_suggestions_widget.cpp | 3 +- .../chat_helpers/spellchecker_common.cpp | 7 ++-- Telegram/SourceFiles/data/data_chat.cpp | 4 +-- Telegram/SourceFiles/data/data_document.cpp | 2 +- Telegram/SourceFiles/data/data_histories.cpp | 3 +- Telegram/SourceFiles/data/data_peer.cpp | 2 +- Telegram/SourceFiles/data/data_poll.cpp | 2 +- Telegram/SourceFiles/data/data_session.cpp | 5 +-- Telegram/SourceFiles/data/data_wall_paper.cpp | 4 +-- .../view/history_view_context_menu.cpp | 36 +++++++------------ Telegram/SourceFiles/info/info_top_bar.cpp | 5 +-- .../info/media/info_media_list_widget.cpp | 8 ++--- .../streaming/media_streaming_reader.cpp | 3 +- .../mtproto/mtproto_dc_options.cpp | 2 +- .../passport/passport_form_controller.cpp | 6 ++-- .../passport_form_view_controller.cpp | 5 ++- .../passport/passport_panel_edit_scans.cpp | 9 +++-- .../platform/linux/specific_linux.cpp | 4 +-- .../SourceFiles/platform/mac/mac_touchbar.mm | 2 +- .../SourceFiles/settings/settings_codes.cpp | 4 +-- .../storage/download_manager_mtproto.cpp | 4 +-- .../window/themes/window_theme_editor_box.cpp | 3 +- 33 files changed, 71 insertions(+), 105 deletions(-) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index d693d1280..1b099628e 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1811,9 +1811,7 @@ void Updates::feedUpdate(const MTPUpdate &update) { return !session().data().folderLoaded(data.vfolder_id().v); }); }; - const auto allLoaded = ranges::find_if(order, notLoaded) - == order.end(); - if (!allLoaded) { + if (!ranges::none_of(order, notLoaded)) { return false; } session().data().applyPinnedChats(folder, order); diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index c4a5eb26f..cea6bc17d 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3578,8 +3578,8 @@ void ApiWrap::addChatParticipants( }).afterDelay(crl::time(5)).send(); } } else if (const auto channel = peer->asChannel()) { - const auto bot = ranges::find_if(users, &UserData::isBot); - if (!peer->isMegagroup() && bot != end(users)) { + const auto hasBot = ranges::any_of(users, &UserData::isBot); + if (!peer->isMegagroup() && hasBot) { ShowAddParticipantsError("USER_BOT", peer, users); return; } diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 94dc88f20..891f9e209 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -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); diff --git a/Telegram/SourceFiles/boxes/auto_download_box.cpp b/Telegram/SourceFiles/boxes/auto_download_box.cpp index 9adae78c1..ad16367d5 100644 --- a/Telegram/SourceFiles/boxes/auto_download_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_download_box.cpp @@ -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( 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) { diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index fd63f3891..2aaeb3f6c 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -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( diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 51446bb1c..15c8cdcdf 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -678,10 +678,7 @@ auto DeleteMessagesBox::revokeText(not_null 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 diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index ac25ca944..579516eed 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -1028,7 +1028,7 @@ void ProxiesBoxController::ShowApplyConfirmation( : QString()); *box = Ui::show(Box(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( diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 321b88153..97fb5d1ae 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -724,9 +724,8 @@ void Options::removeDestroyed(not_null 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); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index a0c331060..5d7d71024 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -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) { diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 2594bfd64..57f9faa2e 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -62,10 +62,7 @@ enum class ButtonType { }; inline bool CanAddUrls(const QList &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) { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index 5897e014f..50465dd7e 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -205,7 +205,7 @@ void AppendLegacySuggestions( && (ch != '-') && (ch != '+'); }; - if (ranges::find_if(query, badSuggestionChar) != query.end()) { + if (ranges::any_of(query, badSuggestionChar)) { return; } diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp index d5df3086d..c46463af4 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp @@ -101,8 +101,7 @@ auto SuggestionsWidget::getRowsByQuery() const -> std::vector { return false; } // Suggest :D and :-P only as exact matches. - return ranges::find_if(_query, [](QChar ch) { return ch.isLower(); }) - == _query.end(); + return ranges::none_of(_query, [](QChar ch) { return ch.isLower(); }); }(); const auto exact = !middle || simple; const auto list = Core::App().emojiKeywords().query(real, exact); diff --git a/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp b/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp index 1b01ee48f..e681dd3a6 100644 --- a/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp +++ b/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp @@ -119,9 +119,9 @@ void EnsurePath() { } bool IsGoodPartName(const QString &name) { - return ranges::find_if(kDictExtensions, [&](const auto &ext) { + return ranges::any_of(kDictExtensions, [&](const auto &ext) { return name.endsWith(ext); - }) != end(kDictExtensions); + }); } using DictLoaderPtr = std::shared_ptr>; @@ -268,11 +268,10 @@ bool DictionaryExists(int langId) { return true; } const auto folder = DictPathByLangId(langId) + '/'; - const auto bad = ranges::find_if(kDictExtensions, [&](const auto &ext) { + return ranges::none_of(kDictExtensions, [&](const auto &ext) { const auto name = Spellchecker::LocaleFromLangId(langId).name(); return !QFile(folder + name + '.' + ext).exists(); }); - return (bad == end(kDictExtensions)); } bool RemoveDictionary(int langId) { diff --git a/Telegram/SourceFiles/data/data_chat.cpp b/Telegram/SourceFiles/data/data_chat.cpp index 502cb2595..5cabfff25 100644 --- a/Telegram/SourceFiles/data/data_chat.cpp +++ b/Telegram/SourceFiles/data/data_chat.cpp @@ -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; } } diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index b29e898ae..0c7087576 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -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 { diff --git a/Telegram/SourceFiles/data/data_histories.cpp b/Telegram/SourceFiles/data/data_histories.cpp index 7345791b1..aeda2a45e 100644 --- a/Telegram/SourceFiles/data/data_histories.cpp +++ b/Telegram/SourceFiles/data/data_histories.cpp @@ -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( diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 6a50820ae..aab888f74 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -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(); diff --git a/Telegram/SourceFiles/data/data_poll.cpp b/Telegram/SourceFiles/data/data_poll.cpp index e31c2145d..1ae50280f 100644 --- a/Telegram/SourceFiles/data/data_poll.cpp +++ b/Telegram/SourceFiles/data/data_poll.cpp @@ -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 { diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 5716349d6..70f8ea260 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -3822,10 +3822,7 @@ void Session::setWallpapers(const QVector &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( u":/gui/arg/bg.jpg"_q)); diff --git a/Telegram/SourceFiles/data/data_wall_paper.cpp b/Telegram/SourceFiles/data/data_wall_paper.cpp index caa8fc5ec..cd50580ef 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.cpp +++ b/Telegram/SourceFiles/data/data_wall_paper.cpp @@ -51,11 +51,11 @@ std::optional MaybeColorFromSerialized(quint32 serialized) { std::optional 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) { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 886ce9864..1584fa462 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -245,9 +245,9 @@ void AddPostLinkAction( MessageIdsList ExtractIdsList(const SelectedItems &items) { return ranges::view::all( items - ) | ranges::view::transform([](const auto &item) { - return item.msgId; - }) | ranges::to_vector; + ) | ranges::view::transform( + &SelectedItem::msgId + ) | ranges::to_vector; } bool AddForwardSelectedAction( @@ -257,9 +257,7 @@ bool AddForwardSelectedAction( if (!request.overSelection || request.selectedItems.empty()) { return false; } - if (ranges::find_if(request.selectedItems, [](const auto &item) { - return !item.canForward; - }) != end(request.selectedItems)) { + if (!ranges::all_of(request.selectedItems, &SelectedItem::canForward)) { return false; } @@ -292,9 +290,7 @@ bool AddForwardMessageAction( const auto asGroup = (request.pointState != PointState::GroupPart); if (asGroup) { if (const auto group = owner->groups().find(item)) { - if (ranges::find_if(group->items, [](auto item) { - return !item->allowsForward(); - }) != end(group->items)) { + if (!ranges::all_of(group->items, &HistoryItem::allowsForward)) { return false; } } @@ -327,9 +323,7 @@ bool AddSendNowSelectedAction( if (!request.overSelection || request.selectedItems.empty()) { return false; } - if (ranges::find_if(request.selectedItems, [](const auto &item) { - return !item.canSendNow; - }) != end(request.selectedItems)) { + if (!ranges::all_of(request.selectedItems, &SelectedItem::canSendNow)) { return false; } @@ -340,9 +334,9 @@ bool AddSendNowSelectedAction( return session->data().message(item.msgId); }) | ranges::view::filter([](HistoryItem *item) { return item != nullptr; - }) | ranges::view::transform([](not_null item) { - return item->history(); - }); + }) | ranges::view::transform( + &HistoryItem::history + ); if (histories.begin() == histories.end()) { return false; } @@ -376,9 +370,7 @@ bool AddSendNowMessageAction( const auto asGroup = (request.pointState != PointState::GroupPart); if (asGroup) { if (const auto group = owner->groups().find(item)) { - if (ranges::find_if(group->items, [](auto item) { - return !item->allowsSendNow(); - }) != end(group->items)) { + if (!ranges::all_of(group->items, &HistoryItem::allowsSendNow)) { return false; } } @@ -464,9 +456,7 @@ bool AddDeleteSelectedAction( if (!request.overSelection || request.selectedItems.empty()) { return false; } - if (ranges::find_if(request.selectedItems, [](const auto &item) { - return !item.canDelete; - }) != end(request.selectedItems)) { + if (!ranges::all_of(request.selectedItems, &SelectedItem::canDelete)) { return false; } @@ -499,10 +489,10 @@ bool AddDeleteMessageAction( const auto asGroup = (request.pointState != PointState::GroupPart); if (asGroup) { if (const auto group = owner->groups().find(item)) { - if (ranges::find_if(group->items, [](auto item) { + if (ranges::any_of(group->items, [](auto item) { const auto id = ItemIdAcrossData(item); return !IsServerMsgId(id) || !item->canDelete(); - }) != end(group->items)) { + })) { return false; } } diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index 3ee262b13..be7b14c3c 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -480,10 +480,7 @@ void TopBar::createSelectionControls() { } bool TopBar::computeCanDelete() const { - return ranges::find_if( - _selectedItems.list, - [](const SelectedItem &item) { return !item.canDelete; } - ) == _selectedItems.list.end(); + return ranges::all_of(_selectedItems.list, &SelectedItem::canDelete); } Ui::StringWithNumbers TopBar::generateSelectedText() const { diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index b39d4c15d..7ad029129 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1280,14 +1280,14 @@ void ListWidget::showContextMenu( } auto canDeleteAll = [&] { - return ranges::find_if(_selected, [](auto &&item) { + return ranges::none_of(_selected, [](auto &&item) { return !item.second.canDelete; - }) == _selected.end(); + }); }; auto canForwardAll = [&] { - return ranges::find_if(_selected, [](auto &&item) { + return ranges::none_of(_selected, [](auto &&item) { return !item.second.canForward; - }) == _selected.end(); + }); }; auto link = ClickHandler::getActive(); diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp index fba6d6239..d204cf910 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp @@ -514,10 +514,9 @@ bool Reader::Slices::checkFullInCache() const { if (isFullInHeader()) { return (_header.flags & Flag::FullInCache); } - const auto i = ranges::find_if(_data, [](const Slice &slice) { + return ranges::none_of(_data, [](const Slice &slice) { return !(slice.flags & Flag::FullInCache); }); - return (i == end(_data)); } void Reader::Slices::processPart( diff --git a/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp b/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp index d2a54fc8c..bb9211567 100644 --- a/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp +++ b/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp @@ -742,7 +742,7 @@ void DcOptions::FilterIfHasWithFlag(Variants &variants, Flag flag) { return (endpoint.flags & flag) != 0; }; const auto has = [&](const std::vector &list) { - return ranges::find_if(list, is) != end(list); + return ranges::any_of(list, is); }; for (auto &byAddress : variants.data) { for (auto &list : byAddress) { diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 80d91a9d3..5274b998a 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -502,15 +502,15 @@ bool Value::uploadingScan() const { }; const auto uploadingInList = [&](FileType type) { const auto &list = filesInEdit(type); - return ranges::find_if(list, uploading) != end(list); + return ranges::any_of(list, uploading); }; if (uploadingInList(FileType::Scan) || uploadingInList(FileType::Translation)) { return true; } - if (ranges::find_if(specialScansInEdit, [&](const auto &pair) { + if (ranges::any_of(specialScansInEdit, [&](const auto &pair) { return uploading(pair.second); - }) != end(specialScansInEdit)) { + })) { return true; } return false; diff --git a/Telegram/SourceFiles/passport/passport_form_view_controller.cpp b/Telegram/SourceFiles/passport/passport_form_view_controller.cpp index 8846993ba..1c07cb080 100644 --- a/Telegram/SourceFiles/passport/passport_form_view_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_view_controller.cpp @@ -73,15 +73,14 @@ bool InlineDetails( if (count != 1) { return false; } - const auto has = ranges::find_if( + return ranges::any_of( request, [&](const std::vector &types) { Expects(!types.empty()); return (types[0] == details); } - ) != end(request); - return has; + ); } bool InlineDetails(const Form::Request &request, Value::Type details) { diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index 41c8fad77..839e2e072 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -186,16 +186,15 @@ bool EditScans::List::uploadMoreRequired() const { if (!upload) { return false; } - const auto exists = ranges::find_if( + const auto exists = ranges::any_of( files, - [](const ScanInfo &file) { return !file.deleted; }) != end(files); + [](const ScanInfo &file) { return !file.deleted; }); if (!exists) { return true; } - const auto errorExists = ranges::find_if( + const auto errorExists = ranges::any_of( files, - [](const ScanInfo &file) { return !file.error.isEmpty(); } - ) != end(files); + [](const ScanInfo &file) { return !file.error.isEmpty(); }); return (errorExists || uploadMoreError) && !uploadedSomeMore(); } diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 258938e62..f348f4b52 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -879,9 +879,9 @@ bool OpenSystemSettings(SystemSettingsType type) { add("pavucontrol-qt"); add("pavucontrol"); add("alsamixergui"); - return ranges::find_if(options, [](const QString &command) { + return ranges::any_of(options, [](const QString &command) { return QProcess::startDetached(command); - }) != end(options); + }); } return true; } diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index c1b77c3d5..941beae56 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -805,7 +805,7 @@ void AppendEmojiPacks( }; const auto checkState = [&](const auto &states) { - return ranges::find(states, gesture.state) != end(states); + return ranges::contains(states, gesture.state); }; if (checkState(kGestureStateProcessed)) { diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index bdd22c2e2..dda0d5999 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -240,9 +240,9 @@ void CodesFeedString(SessionController *window, const QString &text) { } if (found) break; - found = ranges::find_if(codes, [&](const auto &pair) { + found = ranges::any_of(codes, [&](const auto &pair) { return pair.first.startsWith(piece); - }) != end(codes); + }); if (found) break; ++from; diff --git a/Telegram/SourceFiles/storage/download_manager_mtproto.cpp b/Telegram/SourceFiles/storage/download_manager_mtproto.cpp index 4dadef241..53d87ec1b 100644 --- a/Telegram/SourceFiles/storage/download_manager_mtproto.cpp +++ b/Telegram/SourceFiles/storage/download_manager_mtproto.cpp @@ -268,11 +268,11 @@ void DownloadManagerMtproto::requestSucceeded( ).arg(data.maxWaitedAmount)); } data.successes = std::min(data.successes + 1, kMaxTrackedSuccesses); - const auto notEnough = ranges::find_if( + const auto notEnough = ranges::any_of( dc.sessions, _1 < (dc.sessionRemoveTimes + 1) * kRetryAddSessionSuccesses, &DcSessionBalanceData::successes); - if (notEnough != end(dc.sessions)) { + if (notEnough) { return; } for (auto &session : dc.sessions) { diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 71a8c09ce..7c6ad5790 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -400,13 +400,12 @@ bool CopyColorsToPalette( if (slug.size() < kMinSlugSize || slug.size() > kMaxSlugSize) { return false; } - const auto i = ranges::find_if(slug, [](QChar ch) { + return ranges::none_of(slug, [](QChar ch) { return (ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && (ch != '_'); }); - return (i == slug.end()); } SendMediaReady PrepareThemeMedia(