Added references to structured bindings since Apple clang supports them.

This commit is contained in:
23rd 2024-01-09 20:32:18 +03:00 committed by John Preston
parent 6516c7aef3
commit a1369aaad0
33 changed files with 58 additions and 58 deletions

View file

@ -162,7 +162,7 @@ void AutoDownloadBox::setupContent() {
*downloadValues,
*autoPlayValues);
auto allowMore = values | ranges::views::filter([&](Pair pair) {
const auto [type, enabled] = pair;
const auto &[type, enabled] = pair;
const auto value = enabled ? limitByType(type) : 0;
const auto old = settings->bytesLimit(_source, type);
return (old < value);
@ -170,7 +170,7 @@ void AutoDownloadBox::setupContent() {
return pair.first;
});
const auto less = ranges::any_of(*autoPlayValues, [&](Pair pair) {
const auto [type, enabled] = pair;
const auto &[type, enabled] = pair;
const auto value = enabled ? limitByType(type) : 0;
return value < settings->bytesLimit(_source, type);
});
@ -179,7 +179,7 @@ void AutoDownloadBox::setupContent() {
allowMore.end());
const auto changed = ranges::any_of(values, [&](Pair pair) {
const auto [type, enabled] = pair;
const auto &[type, enabled] = pair;
const auto value = enabled ? limitByType(type) : 0;
return value != settings->bytesLimit(_source, type);
});

View file

@ -748,7 +748,7 @@ void ProxiesBox::applyView(View &&view) {
const auto wrap = _wrap
? _wrap.data()
: _initialWrap.data();
const auto [i, ok] = _rows.emplace(id, nullptr);
const auto &[i, ok] = _rows.emplace(id, nullptr);
i->second.reset(wrap->insert(
0,
object_ptr<ProxyRow>(

View file

@ -1121,7 +1121,7 @@ void LanguageBox::prepare() {
using namespace rpl::mappers;
const auto [recent, official] = PrepareLists();
const auto &[recent, official] = PrepareLists();
const auto inner = setInnerWidget(
object_ptr<Content>(this, recent, official),
st::boxScroll,

View file

@ -882,7 +882,7 @@ auto ShareBox::Inner::getChat(not_null<Dialogs::Row*> row)
row->attached = i->second.get();
return i->second.get();
}
const auto [i, ok] = _dataMap.emplace(
const auto &[i, ok] = _dataMap.emplace(
peer,
std::make_unique<Chat>(peer, _st.item, [=] { repaintChat(peer); }));
updateChatName(i->second.get());

View file

@ -3013,7 +3013,7 @@ void GroupCall::checkLastSpoke() {
const auto now = crl::now();
auto list = base::take(_lastSpoke);
for (auto i = list.begin(); i != list.end();) {
const auto [ssrc, when] = *i;
const auto &[ssrc, when] = *i;
if (when.anything + kKeepInListFor >= now) {
hasRecent = true;
++i;

View file

@ -247,7 +247,7 @@ void Row::paintPreview(QPainter &p) const {
const auto width = st::manageEmojiPreviewWidth;
const auto height = st::manageEmojiPreviewWidth;
auto &&preview = ranges::views::zip(_preview, ranges::views::ints(0, int(_preview.size())));
for (const auto [pixmap, index] : preview) {
for (const auto &[pixmap, index] : preview) {
const auto row = (index / 2);
const auto column = (index % 2);
const auto left = x + (column ? width - st::manageEmojiPreview : 0);

View file

@ -128,7 +128,7 @@ CloudPasswordResult ComputeCheck(
}
};
const auto [a, AForHash, u] = GenerateAndCheckRandom();
const auto &[a, AForHash, u] = GenerateAndCheckRandom();
const auto g_b = BigNum::ModSub(B, kg_x, p, context);
if (!MTP::IsGoodModExpFirst(g_b, p)) {
LOG(("API Error: Bad g_b in cloud password check!"));

View file

@ -402,7 +402,7 @@ void Manager::fillDefaults() {
kShowFolder,
ranges::views::ints(1, ranges::unreachable));
for (const auto [command, index] : folders) {
for (const auto &[command, index] : folders) {
set(u"%1+%2"_q.arg(ctrl).arg(index), command);
}
@ -410,7 +410,7 @@ void Manager::fillDefaults() {
kShowAccount,
ranges::views::ints(1, ranges::unreachable));
for (const auto [command, index] : accounts) {
for (const auto &[command, index] : accounts) {
set(u"%1+shift+%2"_q.arg(ctrl).arg(index), command);
}

View file

@ -56,7 +56,7 @@ rpl::producer<UpdateType> Changes::Manager<DataType, UpdateType>::updates(
Flags flags) const {
return _stream.events(
) | rpl::filter([=](const UpdateType &update) {
const auto [updateData, updateFlags] = update;
const auto &[updateData, updateFlags] = update;
return (updateData == data) && (updateFlags & flags);
});
}

View file

@ -847,7 +847,7 @@ void GroupCall::requestUnknownParticipants() {
auto result = base::flat_map<uint32, LastSpokeTimes>();
result.reserve(kRequestPerPage);
while (result.size() < kRequestPerPage) {
const auto [ssrc, when] = _unknownSpokenSsrcs.back();
const auto &[ssrc, when] = _unknownSpokenSsrcs.back();
result.emplace(ssrc, when);
_unknownSpokenSsrcs.erase(_unknownSpokenSsrcs.end() - 1);
}
@ -863,7 +863,7 @@ void GroupCall::requestUnknownParticipants() {
result.reserve(available);
while (result.size() < available) {
const auto &back = _unknownSpokenPeerIds.back();
const auto [participantPeerId, when] = back;
const auto &[participantPeerId, when] = back;
result.emplace(participantPeerId, when);
_unknownSpokenPeerIds.erase(_unknownSpokenPeerIds.end() - 1);
}

View file

@ -123,7 +123,7 @@ not_null<History*> Histories::findOrCreate(PeerId peerId) {
if (const auto result = find(peerId)) {
return result;
}
const auto [i, ok] = _map.emplace(
const auto &[i, ok] = _map.emplace(
peerId,
std::make_unique<History>(&owner(), peerId));
return i->second.get();
@ -355,7 +355,7 @@ void Histories::requestDialogEntry(
return;
}
const auto [j, ok] = _dialogRequestsPending.try_emplace(history);
const auto &[j, ok] = _dialogRequestsPending.try_emplace(history);
if (callback) {
j->second.push_back(std::move(callback));
}
@ -1130,7 +1130,7 @@ void Histories::finishSentRequest(
if (state->postponedRequestEntry && !postponeEntryRequest(*state)) {
const auto i = _dialogRequests.find(history);
Assert(i != end(_dialogRequests));
const auto [j, ok] = _dialogRequestsPending.emplace(
const auto &[j, ok] = _dialogRequestsPending.emplace(
history,
std::move(i->second));
Assert(ok);

View file

@ -1097,7 +1097,7 @@ void Session::watchForOffline(not_null<UserData*> user, TimeId now) {
return;
}
const auto till = user->onlineTill;
const auto [i, ok] = _watchingForOffline.emplace(user, till);
const auto &[i, ok] = _watchingForOffline.emplace(user, till);
if (!ok) {
if (i->second == till) {
return;
@ -1626,7 +1626,7 @@ HistoryItem *Session::changeMessageId(PeerId peerId, MsgId wasId, MsgId nowId) {
}
const auto item = i->second;
list->erase(i);
const auto [j, ok] = list->emplace(nowId, item);
const auto &[j, ok] = list->emplace(nowId, item);
if (!peerIsChannel(peerId)) {
if (IsServerMsgId(wasId)) {
@ -1789,7 +1789,7 @@ void Session::registerHighlightProcess(
not_null<HistoryItem*> item) {
Expects(item->inHighlightProcess());
const auto [i, ok] = _highlightings.emplace(processId, item);
const auto &[i, ok] = _highlightings.emplace(processId, item);
Ensures(ok);
}
@ -4208,7 +4208,7 @@ not_null<Folder*> Session::folder(FolderId id) {
if (const auto result = folderLoaded(id)) {
return result;
}
const auto [it, ok] = _folders.emplace(
const auto &[it, ok] = _folders.emplace(
id,
std::make_unique<Folder>(this, id));
return it->second.get();

View file

@ -234,7 +234,7 @@ Story *Stories::applySingle(PeerId peerId, const MTPstoryItem &story) {
void Stories::requestPeerStories(
not_null<PeerData*> peer,
Fn<void()> done) {
const auto [i, ok] = _requestingPeerStories.emplace(peer);
const auto &[i, ok] = _requestingPeerStories.emplace(peer);
if (done) {
i->second.push_back(std::move(done));
}

View file

@ -2458,7 +2458,7 @@ void InnerWidget::appendToFiltered(Key key) {
}
auto row = std::make_unique<Row>(key, 0, 0);
row->recountHeight(_narrowRatio);
const auto [i, ok] = _filterResultsGlobal.emplace(key, std::move(row));
const auto &[i, ok] = _filterResultsGlobal.emplace(key, std::move(row));
const auto height = filteredHeight();
_filterResults.emplace_back(i->second.get());
_filterResults.back().top = height;
@ -3913,7 +3913,7 @@ void InnerWidget::setupShortcuts() {
auto &&folders = ranges::views::zip(
Shortcuts::kShowFolder,
ranges::views::ints(0, ranges::unreachable));
for (const auto [command, index] : folders) {
for (const auto &[command, index] : folders) {
const auto select = (command == Command::ShowFolderLast)
? (filtersCount - 1)
: std::clamp(index, 0, filtersCount - 1);
@ -3940,7 +3940,7 @@ void InnerWidget::setupShortcuts() {
auto &&pinned = ranges::views::zip(
kPinned,
ranges::views::ints(0, ranges::unreachable));
for (const auto [command, index] : pinned) {
for (const auto &[command, index] : pinned) {
request->check(command) && request->handle([=, index = index] {
const auto list = (_filterId
? session().data().chatsFilters().chatsList(_filterId)

View file

@ -212,8 +212,8 @@ void Crop::computeDownState(const QPoint &p) {
const auto edge = mouseState(p);
const auto &inner = _innerRect;
const auto &crop = _cropPaint;
const auto [iLeft, iTop, iRight, iBottom] = RectEdges(inner);
const auto [cLeft, cTop, cRight, cBottom] = RectEdges(crop);
const auto &[iLeft, iTop, iRight, iBottom] = RectEdges(inner);
const auto &[cLeft, cTop, cRight, cBottom] = RectEdges(crop);
_down = InfoAtDown{
.rect = crop,
.edge = edge,

View file

@ -1553,7 +1553,7 @@ void ApiWrap::appendChatsSlice(
continue;
}
}
const auto [i, ok] = process.indexByPeer.emplace(
const auto &[i, ok] = process.indexByPeer.emplace(
info.peerId,
nextIndex);
if (ok) {

View file

@ -1563,7 +1563,7 @@ QByteArray HtmlWriter::Wrap::pushStickerMedia(
const QString &basePath) {
using namespace Data;
const auto [thumb, size] = WriteImageThumb(
const auto &[thumb, size] = WriteImageThumb(
basePath,
data.file.relativePath,
CalculateThumbSize(
@ -1730,7 +1730,7 @@ QByteArray HtmlWriter::Wrap::pushPhotoMedia(
const QString &basePath) {
using namespace Data;
const auto [thumb, size] = WriteImageThumb(
const auto &[thumb, size] = WriteImageThumb(
basePath,
data.image.file.relativePath,
CalculateThumbSize(
@ -2790,7 +2790,7 @@ Result HtmlWriter::writeDialogSlice(const Data::MessagesSlice &data) {
_settings.path,
FormatDateText(date)));
}
const auto [info, content] = _chat->pushMessage(
const auto &[info, content] = _chat->pushMessage(
message,
previous,
_dialog,

View file

@ -465,7 +465,7 @@ not_null<HistoryItem*> History::insertItem(
std::unique_ptr<HistoryItem> item) {
Expects(item != nullptr);
const auto [i, ok] = _messages.insert(std::move(item));
const auto &[i, ok] = _messages.insert(std::move(item));
const auto result = i->get();
owner().registerMessage(result);

View file

@ -1992,7 +1992,7 @@ void HistoryInner::mouseActionFinish(
&& !_selected.empty()
&& _selected.cbegin()->second != FullSelection
&& !hasCopyRestriction(_selected.cbegin()->first)) {
const auto [item, selection] = *_selected.cbegin();
const auto &[item, selection] = *_selected.cbegin();
if (const auto view = viewByItem(item)) {
TextUtilities::SetClipboardText(
view->selectedText(selection),
@ -2925,7 +2925,7 @@ TextForMimeData HistoryInner::getSelectedText() const {
return TextForMimeData();
}
if (selected.cbegin()->second != FullSelection) {
const auto [item, selection] = *selected.cbegin();
const auto &[item, selection] = *selected.cbegin();
if (const auto view = viewByItem(item)) {
return view->selectedText(selection);
}

View file

@ -901,7 +901,7 @@ not_null<Element*> ListWidget::enforceViewForItem(
return j->second.get();
}
}
const auto [i, ok] = _views.emplace(
const auto &[i, ok] = _views.emplace(
item,
item->createView(this));
return i->second.get();
@ -1094,7 +1094,7 @@ void ListWidget::repaintScrollDateCallback() {
auto ListWidget::collectSelectedItems() const -> SelectedItems {
auto transformation = [&](const auto &item) {
const auto [itemId, selection] = item;
const auto &[itemId, selection] = item;
auto result = SelectedItem(itemId);
result.canDelete = selection.canDelete;
result.canForward = selection.canForward;
@ -3766,7 +3766,7 @@ void ListWidget::refreshItem(not_null<const Element*> view) {
}
return nullptr;
}();
const auto [i, ok] = _views.emplace(
const auto &[i, ok] = _views.emplace(
item,
item->createView(this, was.get()));
const auto now = i->second.get();

View file

@ -761,7 +761,7 @@ void Poll::draw(Painter &p, const PaintContext &context) const {
auto &&answers = ranges::views::zip(
_answers,
ranges::views::ints(0, int(_answers.size())));
for (const auto [answer, index] : answers) {
for (const auto &[answer, index] : answers) {
const auto animation = _answersAnimation
? &_answersAnimation->data[index]
: nullptr;

View file

@ -39,7 +39,7 @@ bool ChangeItemSelection(
return false;
};
if (selected.size() < MaxSelectedItems) {
const auto [i, ok] = selected.try_emplace(item, selectionData);
const auto &[i, ok] = selected.try_emplace(item, selectionData);
if (ok) {
return true;
}

View file

@ -1720,7 +1720,7 @@ bool OverlayWidget::stateAnimationCallback(crl::time now) {
now += st::mediaviewShowDuration + st::mediaviewHideDuration;
}
for (auto i = begin(_animations); i != end(_animations);) {
const auto [state, started] = *i;
const auto &[state, started] = *i;
updateOverRect(state);
const auto dt = float64(now - started) / st::mediaviewFadeDuration;
if (dt >= 1) {
@ -5494,12 +5494,12 @@ void OverlayWidget::preloadData(int delta) {
for (auto index = from; index != till + 1; ++index) {
auto entity = entityByIndex(index);
if (auto photo = std::get_if<not_null<PhotoData*>>(&entity.data)) {
const auto [i, ok] = photos.emplace((*photo)->createMediaView());
const auto &[i, ok] = photos.emplace((*photo)->createMediaView());
(*i)->wanted(Data::PhotoSize::Small, fileOrigin(entity));
(*photo)->load(fileOrigin(entity), LoadFromCloudOrLocal, true);
} else if (auto document = std::get_if<not_null<DocumentData*>>(
&entity.data)) {
const auto [i, ok] = documents.emplace(
const auto &[i, ok] = documents.emplace(
(*document)->createMediaView());
(*i)->thumbnailWanted(fileOrigin(entity));
if (!(*i)->canBePlayed(entity.item)) {

View file

@ -453,7 +453,7 @@ void StartDedicatedLoader(
ready(nullptr);
};
const auto [username, postId] = location;
const auto &[username, postId] = location;
ResolveChannel(mtp, username, [=, postId = postId](
const MTPInputChannel &channel) {
mtp->send(

View file

@ -1791,7 +1791,7 @@ void FormController::loadFile(File &file) {
return;
}
file.downloadStatus.set(LoadStatus::Status::InProgress, 0);
const auto [j, ok] = _fileLoaders.emplace(
const auto &[j, ok] = _fileLoaders.emplace(
key,
std::make_unique<mtpFileLoader>(
&_controller->session(),
@ -1823,7 +1823,7 @@ void FormController::loadFile(File &file) {
}
void FormController::fileLoadDone(FileKey key, const QByteArray &bytes) {
if (const auto [value, file] = findFile(key); file != nullptr) {
if (const auto &[value, file] = findFile(key); file != nullptr) {
const auto decrypted = DecryptData(
bytes::make_span(bytes),
file->hash,
@ -1843,7 +1843,7 @@ void FormController::fileLoadDone(FileKey key, const QByteArray &bytes) {
}
void FormController::fileLoadProgress(FileKey key, int offset) {
if (const auto [value, file] = findFile(key); file != nullptr) {
if (const auto &[value, file] = findFile(key); file != nullptr) {
file->downloadStatus.set(LoadStatus::Status::InProgress, offset);
if (const auto fileInEdit = findEditFile(key)) {
fileInEdit->fields.downloadStatus = file->downloadStatus;
@ -1853,7 +1853,7 @@ void FormController::fileLoadProgress(FileKey key, int offset) {
}
void FormController::fileLoadFail(FileKey key) {
if (const auto [value, file] = findFile(key); file != nullptr) {
if (const auto &[value, file] = findFile(key); file != nullptr) {
file->downloadStatus.set(LoadStatus::Status::Failed);
if (const auto fileInEdit = findEditFile(key)) {
fileInEdit->fields.downloadStatus = file->downloadStatus;
@ -2591,7 +2591,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
const auto row = CollectRequestedRow(required);
for (const auto &requested : row.values) {
const auto type = requested.type;
const auto [i, ok] = _form.values.emplace(type, Value(type));
const auto &[i, ok] = _form.values.emplace(type, Value(type));
auto &value = i->second;
value.translationRequired = requested.translationRequired;
value.selfieRequired = requested.selfieRequired;

View file

@ -530,7 +530,7 @@ void PanelEditDocument::createDetailsRow(
const auto isoByPhone = Countries::Instance().countryISO2ByPhone(
_controller->bot()->session().user()->phone());
const auto [it, ok] = _details.emplace(
const auto &[it, ok] = _details.emplace(
i,
container->add(Ui::PanelDetailsRow::Create(
container,

View file

@ -804,8 +804,8 @@ void DownloadMtprotoTask::placeSentRequest(
dcId(),
requestData.sessionIndex,
Storage::kDownloadPartSize);
const auto [i, ok1] = _sentRequests.emplace(requestId, requestData);
const auto [j, ok2] = _requestByOffset.emplace(
const auto &[i, ok1] = _sentRequests.emplace(requestId, requestData);
const auto &[j, ok2] = _requestByOffset.emplace(
requestData.offset,
requestId);

View file

@ -359,7 +359,7 @@ void Uploader::upload(
void Uploader::currentFailed() {
auto j = queue.find(uploadingId);
if (j != queue.end()) {
const auto [msgId, file] = std::move(*j);
const auto &[msgId, file] = std::move(*j);
queue.erase(j);
notifyFailed(msgId, file);
}
@ -640,7 +640,7 @@ void Uploader::cancelAll() {
currentFailed();
}
while (!queue.empty()) {
const auto [msgId, file] = std::move(*queue.begin());
const auto &[msgId, file] = std::move(*queue.begin());
queue.erase(queue.begin());
notifyFailed(msgId, file);
}

View file

@ -29,7 +29,7 @@ void SingleChoiceBox(
layout,
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
auto &&ints = ranges::views::ints(0, ranges::unreachable);
for (const auto [i, text] : ranges::views::zip(ints, args.options)) {
for (const auto &[i, text] : ranges::views::zip(ints, args.options)) {
layout->add(
object_ptr<Ui::Radiobutton>(
layout,

View file

@ -324,7 +324,7 @@ void AlbumThumbnail::drawSimpleFrame(QPainter &p, QRect to, QSize size) const {
const auto Round = [](float64 value) {
return int(base::SafeRound(value));
};
const auto [from, fillBlack] = [&] {
const auto &[from, fillBlack] = [&] {
if (previewWidth < width && previewHeight < height) {
const auto toWidth = Round(previewWidth * scaleWidth);
const auto toHeight = Round(previewHeight * scaleHeight);

View file

@ -20,7 +20,7 @@ namespace Ui {
namespace {
[[nodiscard]] int SameFirstPartLength(const QString &a, const QString &b) {
const auto [i, j] = ranges::mismatch(a, b);
const auto &[i, j] = ranges::mismatch(a, b);
return (i - a.begin());
}

View file

@ -309,7 +309,7 @@ System::Timing System::countTiming(
void System::registerThread(not_null<Data::Thread*> thread) {
if (const auto topic = thread->asTopic()) {
const auto [i, ok] = _watchedTopics.emplace(topic, rpl::lifetime());
const auto &[i, ok] = _watchedTopics.emplace(topic, rpl::lifetime());
if (ok) {
topic->destroyed() | rpl::start_with_next([=] {
clearFromTopic(topic);

View file

@ -1243,7 +1243,7 @@ void SessionController::setupShortcuts() {
auto &&accounts = ranges::views::zip(
Shortcuts::kShowAccount,
ranges::views::ints(0, accountsCount));
for (const auto [command, index] : accounts) {
for (const auto &[command, index] : accounts) {
request->check(command) && request->handle([=] {
const auto list = app->domain().orderedAccounts();
if (index >= list.size()) {