From f0e1d2fd02f47d45a2c0864b7fd6cece506310fa Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 31 Aug 2020 13:04:17 +0400 Subject: [PATCH] 'base::optional_variant<' -> 'std::variantdata().message(data)) { if (item->isScheduled()) { const auto &scheduled = _session->data().scheduledMessages(); diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index a45d181169..69426c68d6 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -103,7 +103,7 @@ private: return !(*this == other); } }; - using Selection = base::optional_variant; + using Selection = std::variant; int getSelectionIndex(const Selection &selection) const; void repaintPaper(int index); @@ -358,16 +358,16 @@ void BackgroundBox::Inner::paintPaper( p.drawPixmap(x, y, paper.thumbnail); } - const auto over = _overDown ? _overDown : _over; + const auto over = !v::is_null(_overDown) ? _overDown : _over; if (paper.data.id() == Window::Theme::Background()->id()) { const auto checkLeft = x + st::backgroundSize.width() - st::overviewCheckSkip - st::overviewCheck.size; const auto checkTop = y + st::backgroundSize.height() - st::overviewCheckSkip - st::overviewCheck.size; _check->paint(p, checkLeft, checkTop, width()); } else if (Data::IsCloudWallPaper(paper.data) && !Data::IsDefaultWallPaper(paper.data) - && over.has_value() + && !v::is_null(over) && (&paper == &_papers[getSelectionIndex(over)])) { - const auto deleteSelected = over.is(); + const auto deleteSelected = v::is(over); const auto deletePos = QPoint(x + st::backgroundSize.width() - st::stickerPanDeleteIconBg.width(), y); p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityBgOver : st::stickerPanDeleteOpacityBg); st::stickerPanDeleteIconBg.paint(p, deletePos, width()); @@ -414,7 +414,7 @@ void BackgroundBox::Inner::mouseMoveEvent(QMouseEvent *e) { repaintPaper(getSelectionIndex(_over)); _over = newOver; repaintPaper(getSelectionIndex(_over)); - setCursor((_over.has_value() || _overDown.has_value()) + setCursor((!v::is_null(_over) || !v::is_null(_overDown)) ? style::cur_pointer : style::cur_default); } @@ -442,7 +442,7 @@ void BackgroundBox::Inner::mousePressEvent(QMouseEvent *e) { int BackgroundBox::Inner::getSelectionIndex( const Selection &selection) const { - return selection.match([](const Selected &data) { + return v::match(selection, [](const Selected &data) { return data.index; }, [](const DeleteSelected &data) { return data.index; @@ -452,12 +452,12 @@ int BackgroundBox::Inner::getSelectionIndex( } void BackgroundBox::Inner::mouseReleaseEvent(QMouseEvent *e) { - if (base::take(_overDown) == _over && _over.has_value()) { + if (base::take(_overDown) == _over && !v::is_null(_over)) { const auto index = getSelectionIndex(_over); if (index >= 0 && index < _papers.size()) { - if (base::get_if(&_over)) { + if (std::get_if(&_over)) { _backgroundRemove.fire_copy(_papers[index].data); - } else if (base::get_if(&_over)) { + } else if (std::get_if(&_over)) { auto &paper = _papers[index]; if (!paper.dataMedia) { if (const auto document = paper.data.document()) { @@ -468,7 +468,7 @@ void BackgroundBox::Inner::mouseReleaseEvent(QMouseEvent *e) { _backgroundChosen.fire_copy(paper.data); } } - } else if (!_over.has_value()) { + } else if (v::is_null(_over)) { setCursor(style::cur_default); } } diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 5f30d3eb50..77f73e9e4c 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -489,7 +489,7 @@ void EditCaptionBox::updateEditPreview() { auto isGif = false; auto shouldAsDoc = true; auto docPhotoSize = QSize(); - if (const auto image = base::get_if(fileMedia)) { + if (const auto image = std::get_if(fileMedia)) { shouldAsDoc = !Storage::ValidateThumbDimensions( image->data.width(), image->data.height()); @@ -501,14 +501,14 @@ void EditCaptionBox::updateEditPreview() { _animated = isGif; _photo = !isGif && !shouldAsDoc; _isImage = true; - } else if (const auto video = base::get_if(fileMedia)) { + } else if (const auto video = std::get_if(fileMedia)) { isGif = video->isGifv; _animated = true; shouldAsDoc = false; } if (shouldAsDoc) { auto nameString = filename; - if (const auto song = base::get_if(fileMedia)) { + if (const auto song = std::get_if(fileMedia)) { nameString = DocumentData::ComposeNameString( filename, song->title, @@ -684,7 +684,7 @@ bool EditCaptionBox::fileFromClipboard(not_null data) { const auto imageAsDoc = [&] { using Info = FileMediaInformation; const auto fileMedia = &file->information->media; - if (const auto image = base::get_if(fileMedia)) { + if (const auto image = std::get_if(fileMedia)) { return !Storage::ValidateThumbDimensions( image->data.width(), image->data.height()); diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index 0453094e60..af16dba918 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -105,7 +105,7 @@ private: return (index == other.index); } }; - using Selection = base::optional_variant; + using Selection = std::variant; void updateSelected(Selection selected); void updatePressed(Selection pressed); @@ -327,7 +327,7 @@ void Rows::mouseMoveEvent(QMouseEvent *e) { void Rows::mousePressEvent(QMouseEvent *e) { updatePressed(_selected); - if (_pressed.has_value() + if (!v::is_null(_pressed) && !rowBySelection(_pressed).menuToggleForceRippled) { addRipple(_pressed, e->pos()); } @@ -348,11 +348,11 @@ QRect Rows::menuToggleArea(not_null row) const { } void Rows::addRipple(Selection selected, QPoint position) { - Expects(selected.has_value()); + Expects(!v::is_null(selected)); ensureRippleBySelection(selected); - const auto menu = selected.is(); + const auto menu = v::is(selected); const auto &row = rowBySelection(selected); const auto menuArea = menuToggleArea(&row); auto &ripple = rippleBySelection(&row, selected); @@ -369,7 +369,7 @@ void Rows::ensureRippleBySelection(not_null row, Selection selected) { if (ripple) { return; } - const auto menu = selected.is(); + const auto menu = v::is(selected); const auto menuArea = menuToggleArea(row); auto mask = menu ? Ui::RippleAnimation::ellipseMask(menuArea.size()) @@ -391,7 +391,7 @@ void Rows::mouseReleaseEvent(QMouseEvent *e) { const auto pressed = _pressed; updatePressed({}); if (pressed == _selected) { - pressed.match([&](RowSelection data) { + v::match(pressed, [&](RowSelection data) { activateByIndex(data.index); }, [&](MenuSelection data) { showMenu(data.index); @@ -597,7 +597,7 @@ int Rows::count() const { } int Rows::indexFromSelection(Selection selected) const { - return selected.match([&](RowSelection data) { + return v::match(selected, [&](RowSelection data) { return data.index; }, [&](MenuSelection data) { return data.index; @@ -648,7 +648,7 @@ rpl::producer Rows::isEmpty() const { } void Rows::repaint(Selection selected) { - selected.match([](v::null_t) { + v::match(selected, [](v::null_t) { }, [&](const auto &data) { repaint(data.index); }); @@ -672,17 +672,17 @@ void Rows::repaintChecked(not_null row) { } void Rows::updateSelected(Selection selected) { - const auto changed = (_selected.has_value() != selected.has_value()); + const auto changed = (v::is_null(_selected) != v::is_null(selected)); repaint(_selected); _selected = selected; repaint(_selected); if (changed) { - _hasSelection.fire(_selected.has_value()); + _hasSelection.fire(!v::is_null(_selected)); } } void Rows::updatePressed(Selection pressed) { - if (_pressed.has_value()) { + if (!v::is_null(_pressed)) { if (!rowBySelection(_pressed).menuToggleForceRippled) { if (const auto ripple = rippleBySelection(_pressed).get()) { ripple->lastStop(); @@ -725,7 +725,7 @@ const std::unique_ptr &Rows::rippleBySelection( std::unique_ptr &Rows::rippleBySelection( not_null row, Selection selected) { - return selected.is() + return v::is(selected) ? row->menuToggleRipple : row->ripple; } @@ -796,7 +796,7 @@ void Rows::paintEvent(QPaintEvent *e) { const auto menu = menuToggleArea(); const auto selectedIndex = (_menuShownIndex >= 0) ? _menuShownIndex - : indexFromSelection(_pressed.has_value() ? _pressed : _selected); + : indexFromSelection(!v::is_null(_pressed) ? _pressed : _selected); for (auto i = 0, till = count(); i != till; ++i) { const auto &row = rowByIndex(i); if (row.top + row.height <= clip.y()) { diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index ab8c9d7219..e47cf979c5 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -766,11 +766,11 @@ SingleMediaPreview *SingleMediaPreview::Create( auto preview = QImage(); bool animated = false; bool animationPreview = false; - if (const auto image = base::get_if( + if (const auto image = std::get_if( &file.information->media)) { preview = image->data; animated = animationPreview = image->animated; - } else if (const auto video = base::get_if( + } else if (const auto video = std::get_if( &file.information->media)) { preview = video->thumbnail; animated = true; @@ -1004,10 +1004,10 @@ void SingleFilePreview::prepareThumb(const QImage &preview) { void SingleFilePreview::preparePreview(const Storage::PreparedFile &file) { auto preview = QImage(); - if (const auto image = base::get_if( + if (const auto image = std::get_if( &file.information->media)) { preview = image->data; - } else if (const auto video = base::get_if( + } else if (const auto video = std::get_if( &file.information->media)) { preview = video->thumbnail; } @@ -1034,7 +1034,7 @@ void SingleFilePreview::preparePreview(const Storage::PreparedFile &file) { auto songTitle = QString(); auto songPerformer = QString(); if (file.information) { - if (const auto song = base::get_if( + if (const auto song = std::get_if( &file.information->media)) { songTitle = song->title; songPerformer = song->performer; diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index d4cd733c71..c70fa623c5 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -179,7 +179,7 @@ private: return false; } }; - using SelectedRow = base::optional_variant; + using SelectedRow = std::variant; class AddressField : public Ui::UsernameInput { public: using UsernameInput::UsernameInput; @@ -1101,7 +1101,7 @@ void StickersBox::Inner::paintRow(Painter &p, not_null row, int index) { if (_megagroupSet) { auto selectedIndex = [&] { - if (auto index = base::get_if(&_selected)) { + if (auto index = std::get_if(&_selected)) { return *index; } return -1; @@ -1341,7 +1341,7 @@ void StickersBox::Inner::mousePressEvent(QMouseEvent *e) { if (_actionSel >= 0) { setActionDown(_actionSel); update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight); - } else if (auto selectedIndex = base::get_if(&_selected)) { + } else if (auto selectedIndex = std::get_if(&_selected)) { if (_section == Section::Installed && !_rows[*selectedIndex]->isRecentSet() && _inDragArea) { _above = _dragging = _started = *selectedIndex; _dragStart = mapFromGlobal(_mouse); @@ -1394,7 +1394,7 @@ void StickersBox::Inner::setSelected(SelectedRow selected) { return; } auto countSelectedIndex = [&] { - if (auto index = base::get_if(&_selected)) { + if (auto index = std::get_if(&_selected)) { return *index; } return -1; @@ -1416,7 +1416,7 @@ void StickersBox::Inner::setPressed(SelectedRow pressed) { return; } auto countPressedIndex = [&] { - if (auto index = base::get_if(&_pressed)) { + if (auto index = std::get_if(&_pressed)) { return *index; } return -1; @@ -1544,7 +1544,7 @@ void StickersBox::Inner::updateCursor() { ? ((_actionSel >= 0 && (_actionDown < 0 || _actionDown == _actionSel)) ? style::cur_pointer : style::cur_default) - : (_selected.has_value() || _pressed.has_value()) + : (!v::is_null(_selected) || !v::is_null(_pressed)) ? style::cur_pointer : style::cur_default); } @@ -1582,7 +1582,7 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { _dragging = _started = -1; } else if (pressed == _selected && _actionSel < 0 && _actionDown < 0) { const auto selectedIndex = [&] { - if (auto index = base::get_if(&_selected)) { + if (auto index = std::get_if(&_selected)) { return *index; } return -1; @@ -1602,7 +1602,7 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { showSetByRow(*row); } } - } else if (_megagroupSelectedSet && _selected.is()) { + } else if (_megagroupSelectedSet && v::is(_selected)) { showSetByRow(*_megagroupSelectedSet); } } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 31ec40000e..28b35ff148 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1509,8 +1509,10 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { } auto &sets = shownSets(); - auto selectedSticker = base::get_if(&_selected); - auto selectedButton = base::get_if(_pressed ? &_pressed : &_selected); + auto selectedSticker = std::get_if(&_selected); + auto selectedButton = std::get_if(!v::is_null(_pressed) + ? &_pressed + : &_selected); if (sets.empty() && _section == Section::Search) { paintEmptySearchResults(p); @@ -1625,7 +1627,7 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { if (clip.top() + clip.height() <= info.rowsTop) { return true; } else if (set.id == Data::Stickers::MegagroupSetId && set.stickers.empty()) { - auto buttonSelected = (base::get_if(&_selected) != nullptr); + auto buttonSelected = (std::get_if(&_selected) != nullptr); paintMegagroupEmptySet(p, info.rowsTop, buttonSelected); return true; } @@ -1971,20 +1973,20 @@ void StickersListWidget::mousePressEvent(QMouseEvent *e) { } void StickersListWidget::setPressed(OverState newPressed) { - if (auto button = base::get_if(&_pressed)) { + if (auto button = std::get_if(&_pressed)) { auto &sets = shownSets(); Assert(button->section >= 0 && button->section < sets.size()); auto &set = sets[button->section]; if (set.ripple) { set.ripple->lastStop(); } - } else if (base::get_if(&_pressed)) { + } else if (std::get_if(&_pressed)) { if (_megagroupSetButtonRipple) { _megagroupSetButtonRipple->lastStop(); } } _pressed = newPressed; - if (auto button = base::get_if(&_pressed)) { + if (auto button = std::get_if(&_pressed)) { auto &sets = shownSets(); Assert(button->section >= 0 && button->section < sets.size()); auto &set = sets[button->section]; @@ -1992,7 +1994,7 @@ void StickersListWidget::setPressed(OverState newPressed) { set.ripple = createButtonRipple(button->section); } set.ripple->add(mapFromGlobal(QCursor::pos()) - buttonRippleTopLeft(button->section)); - } else if (base::get_if(&_pressed)) { + } else if (std::get_if(&_pressed)) { if (!_megagroupSetButtonRipple) { auto maskSize = _megagroupSetButtonRect.size(); auto mask = Ui::RippleAnimation::roundRectMask(maskSize, st::buttonRadius); @@ -2059,10 +2061,10 @@ void StickersListWidget::fillContextMenu( SendMenu::Type type) { auto selected = _selected; auto &sets = shownSets(); - if (!selected || _pressed) { + if (v::is_null(selected) || !v::is_null(_pressed)) { return; } - if (auto sticker = base::get_if(&selected)) { + if (auto sticker = std::get_if(&selected)) { Assert(sticker->section >= 0 && sticker->section < sets.size()); auto &set = sets[sticker->section]; Assert(sticker->index >= 0 && sticker->index < set.stickers.size()); @@ -2124,8 +2126,8 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { updateSelected(); auto &sets = shownSets(); - if (pressed && pressed == _selected) { - if (auto sticker = base::get_if(&pressed)) { + if (!v::is_null(pressed) && pressed == _selected) { + if (auto sticker = std::get_if(&pressed)) { Assert(sticker->section >= 0 && sticker->section < sets.size()); auto &set = sets[sticker->section]; Assert(sticker->index >= 0 && sticker->index < set.stickers.size()); @@ -2145,10 +2147,10 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { } else { _chosen.fire_copy({ .document = document }); } - } else if (auto set = base::get_if(&pressed)) { + } else if (auto set = std::get_if(&pressed)) { Assert(set->section >= 0 && set->section < sets.size()); displaySet(sets[set->section].id); - } else if (auto button = base::get_if(&pressed)) { + } else if (auto button = std::get_if(&pressed)) { Assert(button->section >= 0 && button->section < sets.size()); if (sets[button->section].externalLayout) { installSet(sets[button->section].id); @@ -2159,7 +2161,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { } else { removeSet(sets[button->section].id); } - } else if (base::get_if(&pressed)) { + } else if (std::get_if(&pressed)) { Ui::show(Box(controller(), _megagroupSet)); } } @@ -2750,7 +2752,7 @@ bool StickersListWidget::preventAutoHide() { } void StickersListWidget::updateSelected() { - if (_pressed && !_previewShown) { + if (!v::is_null(_pressed) && !_previewShown) { return; } @@ -2827,13 +2829,15 @@ bool StickersListWidget::stickerHasDeleteButton(const Set &set, int index) const void StickersListWidget::setSelected(OverState newSelected) { if (_selected != newSelected) { - setCursor(newSelected ? style::cur_pointer : style::cur_default); + setCursor(!v::is_null(newSelected) + ? style::cur_pointer + : style::cur_default); auto &sets = shownSets(); auto updateSelected = [&]() { - if (auto sticker = base::get_if(&_selected)) { + if (auto sticker = std::get_if(&_selected)) { rtlupdate(stickerRect(sticker->section, sticker->index)); - } else if (auto button = base::get_if(&_selected)) { + } else if (auto button = std::get_if(&_selected)) { if (button->section >= 0 && button->section < sets.size() && sets[button->section].externalLayout) { @@ -2841,7 +2845,7 @@ void StickersListWidget::setSelected(OverState newSelected) { } else { rtlupdate(removeButtonRect(button->section)); } - } else if (base::get_if(&_selected)) { + } else if (std::get_if(&_selected)) { rtlupdate(megagroupSetButtonRectFinal()); } }; @@ -2850,7 +2854,7 @@ void StickersListWidget::setSelected(OverState newSelected) { updateSelected(); if (_previewShown && _pressed != _selected) { - if (const auto sticker = base::get_if(&_selected)) { + if (const auto sticker = std::get_if(&_selected)) { _pressed = _selected; Assert(sticker->section >= 0 && sticker->section < sets.size()); const auto &set = sets[sticker->section]; @@ -2865,7 +2869,7 @@ void StickersListWidget::setSelected(OverState newSelected) { } void StickersListWidget::showPreview() { - if (const auto sticker = base::get_if(&_pressed)) { + if (const auto sticker = std::get_if(&_pressed)) { const auto &sets = shownSets(); Assert(sticker->section >= 0 && sticker->section < sets.size()); const auto &set = sets[sticker->section]; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index d9d6378cf9..e773208943 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -144,7 +144,8 @@ private: friend inline bool operator==(OverGroupAdd a, OverGroupAdd b) { return true; } - using OverState = base::optional_variant< + using OverState = std::variant< + v::null_t, OverSticker, OverSet, OverButton, diff --git a/Telegram/SourceFiles/core/core_cloud_password.cpp b/Telegram/SourceFiles/core/core_cloud_password.cpp index a5e979200b..e076ac646f 100644 --- a/Telegram/SourceFiles/core/core_cloud_password.cpp +++ b/Telegram/SourceFiles/core/core_cloud_password.cpp @@ -199,10 +199,10 @@ CloudPasswordCheckRequest ParseCloudPasswordCheckRequest( } CloudPasswordAlgo ValidateNewCloudPasswordAlgo(CloudPasswordAlgo &&parsed) { - if (!parsed.is()) { + if (!v::is(parsed)) { return v::null; } - auto &value = parsed.get_unchecked(); + auto &value = std::get(parsed); const auto already = value.salt1.size(); value.salt1.resize(already + kAdditionalSalt); bytes::set_random(bytes::make_span(value.salt1).subspan(already)); @@ -210,7 +210,7 @@ CloudPasswordAlgo ValidateNewCloudPasswordAlgo(CloudPasswordAlgo &&parsed) { } MTPPasswordKdfAlgo PrepareCloudPasswordAlgo(const CloudPasswordAlgo &data) { - return data.match([](const CloudPasswordAlgoModPow &data) { + return v::match(data, [](const CloudPasswordAlgoModPow &data) { return MTP_passwordKdfAlgoModPow( MTP_bytes(data.salt1), MTP_bytes(data.salt2), @@ -228,7 +228,7 @@ CloudPasswordResult::operator bool() const { bytes::vector ComputeCloudPasswordHash( const CloudPasswordAlgo &algo, bytes::const_span password) { - return algo.match([&](const CloudPasswordAlgoModPow &data) { + return v::match(algo, [&](const CloudPasswordAlgoModPow &data) { return ComputeHash(data, password); }, [](v::null_t) -> bytes::vector { Unexpected("Bad cloud password algorithm."); @@ -238,7 +238,7 @@ bytes::vector ComputeCloudPasswordHash( CloudPasswordDigest ComputeCloudPasswordDigest( const CloudPasswordAlgo &algo, bytes::const_span password) { - return algo.match([&](const CloudPasswordAlgoModPow &data) { + return v::match(algo, [&](const CloudPasswordAlgoModPow &data) { return ComputeDigest(data, password); }, [](v::null_t) -> CloudPasswordDigest { Unexpected("Bad cloud password algorithm."); @@ -248,7 +248,7 @@ CloudPasswordDigest ComputeCloudPasswordDigest( CloudPasswordResult ComputeCloudPasswordCheck( const CloudPasswordCheckRequest &request, bytes::const_span hash) { - return request.algo.match([&](const CloudPasswordAlgoModPow &data) { + return v::match(request.algo, [&](const CloudPasswordAlgoModPow &data) { return ComputeCheck(request, data, hash); }, [](v::null_t) -> CloudPasswordResult { Unexpected("Bad cloud password algorithm."); @@ -270,10 +270,10 @@ SecureSecretAlgo ParseSecureSecretAlgo( } SecureSecretAlgo ValidateNewSecureSecretAlgo(SecureSecretAlgo &&parsed) { - if (!parsed.is()) { + if (!v::is(parsed)) { return v::null; } - auto &value = parsed.get_unchecked(); + auto &value = std::get(parsed); const auto already = value.salt.size(); value.salt.resize(already + kAdditionalSalt); bytes::set_random(bytes::make_span(value.salt).subspan(already)); @@ -282,7 +282,7 @@ SecureSecretAlgo ValidateNewSecureSecretAlgo(SecureSecretAlgo &&parsed) { MTPSecurePasswordKdfAlgo PrepareSecureSecretAlgo( const SecureSecretAlgo &data) { - return data.match([](const SecureSecretAlgoPBKDF2 &data) { + return v::match(data, [](const SecureSecretAlgoPBKDF2 &data) { return MTP_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000( MTP_bytes(data.salt)); }, [](const SecureSecretAlgoSHA512 &data) { @@ -295,7 +295,7 @@ MTPSecurePasswordKdfAlgo PrepareSecureSecretAlgo( bytes::vector ComputeSecureSecretHash( const SecureSecretAlgo &algo, bytes::const_span password) { - return algo.match([&](const auto &data) { + return v::match(algo, [&](const auto &data) { return ComputeHash(data, password); }); } diff --git a/Telegram/SourceFiles/core/core_cloud_password.h b/Telegram/SourceFiles/core/core_cloud_password.h index de5b359c8a..33f9894ef5 100644 --- a/Telegram/SourceFiles/core/core_cloud_password.h +++ b/Telegram/SourceFiles/core/core_cloud_password.h @@ -31,7 +31,7 @@ inline bool operator==( && (a.p == b.p); } -using CloudPasswordAlgo = base::optional_variant; +using CloudPasswordAlgo = std::variant; CloudPasswordAlgo ParseCloudPasswordAlgo(const MTPPasswordKdfAlgo &data); CloudPasswordAlgo ValidateNewCloudPasswordAlgo(CloudPasswordAlgo &&parsed); @@ -43,7 +43,7 @@ struct CloudPasswordCheckRequest { CloudPasswordAlgo algo; explicit operator bool() const { - return !!algo; + return !v::is_null(algo); } }; @@ -106,7 +106,8 @@ inline bool operator==( return (a.salt == b.salt); } -using SecureSecretAlgo = base::optional_variant< +using SecureSecretAlgo = std::variant< + v::null_t, SecureSecretAlgoSHA512, SecureSecretAlgoPBKDF2>; diff --git a/Telegram/SourceFiles/data/data_file_origin.h b/Telegram/SourceFiles/data/data_file_origin.h index 2bafc3bd38..7d9b5d79e0 100644 --- a/Telegram/SourceFiles/data/data_file_origin.h +++ b/Telegram/SourceFiles/data/data_file_origin.h @@ -97,7 +97,8 @@ struct FileOriginTheme { }; struct FileOrigin { - using Variant = base::optional_variant< + using Variant = std::variant< + v::null_t, FileOriginMessage, FileOriginUserPhoto, FileOriginPeerPhoto, @@ -123,7 +124,7 @@ struct FileOrigin { } explicit operator bool() const { - return data.has_value(); + return !v::is_null(data); } inline bool operator<(const FileOrigin &other) const { return data < other.data; diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index c0eeea8d74..9904f4788d 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -858,7 +858,7 @@ Peer EmptyPeer(PeerId peerId) { } File &Media::file() { - return content.match([](Photo &data) -> File& { + return v::match(content, [](Photo &data) -> File& { return data.image.file; }, [](Document &data) -> File& { return data.file; @@ -871,7 +871,7 @@ File &Media::file() { } const File &Media::file() const { - return content.match([](const Photo &data) -> const File& { + return v::match(content, [](const Photo &data) -> const File& { return data.image.file; }, [](const Document &data) -> const File& { return data.file; @@ -884,7 +884,7 @@ const File &Media::file() const { } Image &Media::thumb() { - return content.match([](Document &data) -> Image& { + return v::match(content, [](Document &data) -> Image& { return data.thumb; }, [](auto&) -> Image& { static Image result; @@ -893,7 +893,7 @@ Image &Media::thumb() { } const Image &Media::thumb() const { - return content.match([](const Document &data) -> const Image& { + return v::match(content, [](const Document &data) -> const Image& { return data.thumb; }, [](const auto &) -> const Image& { static const Image result; @@ -1104,7 +1104,7 @@ ServiceAction ParseServiceAction( File &Message::file() { const auto service = &action.content; - if (const auto photo = base::get_if(service)) { + if (const auto photo = std::get_if(service)) { return photo->photo.image.file; } return media.file(); @@ -1112,7 +1112,7 @@ File &Message::file() { const File &Message::file() const { const auto service = &action.content; - if (const auto photo = base::get_if(service)) { + if (const auto photo = std::get_if(service)) { return photo->photo.image.file; } return media.file(); diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h index ac768d6dea..2af60cb5a0 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.h +++ b/Telegram/SourceFiles/export/data/export_data_types.h @@ -309,7 +309,8 @@ struct UnsupportedMedia { }; struct Media { - base::optional_variant< + std::variant< + v::null_t, Photo, Document, SharedContact, @@ -449,7 +450,8 @@ struct ActionPhoneNumberRequest { }; struct ServiceAction { - base::optional_variant< + std::variant< + v::null_t, ActionChatCreate, ActionChatEditTitle, ActionChatEditPhoto, diff --git a/Telegram/SourceFiles/export/export_api_wrap.cpp b/Telegram/SourceFiles/export/export_api_wrap.cpp index f907593f78..88caefa004 100644 --- a/Telegram/SourceFiles/export/export_api_wrap.cpp +++ b/Telegram/SourceFiles/export/export_api_wrap.cpp @@ -1655,8 +1655,8 @@ bool ApiWrap::processFileLoad( } using Type = MediaSettings::Type; - const auto type = message ? message->media.content.match( - [&](const Data::Document &data) { + const auto type = message ? v::match(message->media.content, [&]( + const Data::Document &data) { if (data.isSticker) { return Type::Sticker; } else if (data.isVideoMessage) { diff --git a/Telegram/SourceFiles/export/export_controller.cpp b/Telegram/SourceFiles/export/export_controller.cpp index 896d017c63..6615deed41 100644 --- a/Telegram/SourceFiles/export/export_controller.cpp +++ b/Telegram/SourceFiles/export/export_controller.cpp @@ -161,13 +161,13 @@ rpl::producer ControllerObject::state() const { ) | rpl::then( _stateChanges.events() ) | rpl::filter([](const State &state) { - const auto password = base::get_if(&state); + const auto password = std::get_if(&state); return !password || !password->requesting; }); } void ControllerObject::setState(State &&state) { - if (_state.is()) { + if (v::is(_state)) { return; } _state = std::move(state); diff --git a/Telegram/SourceFiles/export/export_controller.h b/Telegram/SourceFiles/export/export_controller.h index 89b7fd8577..9c060541a6 100644 --- a/Telegram/SourceFiles/export/export_controller.h +++ b/Telegram/SourceFiles/export/export_controller.h @@ -96,7 +96,8 @@ struct FinishedState { int64 bytesCount = 0; }; -using State = base::optional_variant< +using State = std::variant< + v::null_t, PasswordCheckState, ProcessingState, ApiErrorState, diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index 59aea9d0de..e072619d74 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -973,7 +973,7 @@ auto HtmlWriter::Wrap::pushMessage( info.forwardedFromName = message.forwardedFromName; info.forwardedDate = message.forwardedDate; info.forwarded = message.forwarded; - if (message.media.content.is()) { + if (v::is(message.media.content)) { return { info, pushServiceMessage( message.id, dialog, @@ -990,8 +990,8 @@ auto HtmlWriter::Wrap::pushMessage( const auto isChannel = (dialog.type == DialogType::PrivateChannel) || (dialog.type == DialogType::PublicChannel); const auto serviceFrom = peers.wrapUserName(message.fromId); - const auto serviceText = message.action.content.match( - [&](const ActionChatCreate &data) { + const auto serviceText = v::match(message.action.content, [&]( + const ActionChatCreate &data) { return serviceFrom + " created group «" + data.title + "»" + (data.userIds.empty() @@ -1094,8 +1094,8 @@ auto HtmlWriter::Wrap::pushMessage( if (!serviceText.isEmpty()) { const auto &content = message.action.content; - const auto photo = content.is() - ? &content.get_unchecked().photo + const auto photo = v::is(content) + ? &std::get(content).photo : nullptr; return { info, pushServiceMessage( message.id, @@ -1256,7 +1256,7 @@ QByteArray HtmlWriter::Wrap::pushMedia( return pushGenericMedia(data); } const auto &content = message.media.content; - if (const auto document = base::get_if(&content)) { + if (const auto document = std::get_if(&content)) { Assert(!message.media.ttl); if (document->isSticker) { return pushStickerMedia(*document, basePath); @@ -1266,13 +1266,13 @@ QByteArray HtmlWriter::Wrap::pushMedia( return pushVideoFileMedia(*document, basePath); } Unexpected("Non generic document in HtmlWriter::Wrap::pushMedia."); - } else if (const auto photo = base::get_if(&content)) { + } else if (const auto photo = std::get_if(&content)) { Assert(!message.media.ttl); return pushPhotoMedia(*photo, basePath); - } else if (const auto poll = base::get_if(&content)) { + } else if (const auto poll = std::get_if(&content)) { return pushPoll(*poll); } - Assert(!content.has_value()); + Assert(v::is_null(content)); return QByteArray(); } @@ -1602,7 +1602,7 @@ MediaData HtmlWriter::Wrap::prepareMediaData( auto result = MediaData(); const auto &action = message.action; - if (const auto call = base::get_if(&action.content)) { + if (const auto call = std::get_if(&action.content)) { result.classes = "media_call"; result.title = peers.peer(message.out ? message.peerId @@ -1628,7 +1628,7 @@ MediaData HtmlWriter::Wrap::prepareMediaData( return result; } - message.media.content.match([&](const Photo &data) { + v::match(message.media.content, [&](const Photo &data) { if (message.media.ttl) { result.title = "Self-destructing photo"; result.status = data.id diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index dd6b19d1d6..43580ba363 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -221,7 +221,7 @@ QByteArray SerializeMessage( const QString &internalLinksDomain) { using namespace Data; - if (message.media.content.is()) { + if (v::is(message.media.content)) { return SerializeObject(context, { { "id", Data::NumberToString(message.id) }, { "type", SerializeString("unsupported") } @@ -254,7 +254,9 @@ QByteArray SerializeMessage( { "id", NumberToString(message.id) }, { "type", - SerializeString(message.action.content ? "service" : "message") + SerializeString(!v::is_null(message.action.content) + ? "service" + : "message") }, { "date", SerializeDate(message.date) }, }; @@ -357,7 +359,7 @@ QByteArray SerializeMessage( } }; - message.action.content.match([&](const ActionChatCreate &data) { + v::match(message.action.content, [&](const ActionChatCreate &data) { pushActor(); pushAction("create_group"); push("title", data.title); @@ -473,7 +475,7 @@ QByteArray SerializeMessage( pushAction("requested_phone_number"); }, [](v::null_t) {}); - if (!message.action.content) { + if (v::is_null(message.action.content)) { pushFrom(); push("author", message.signature); if (message.forwardedFromId) { @@ -498,7 +500,7 @@ QByteArray SerializeMessage( } } - message.media.content.match([&](const Photo &photo) { + v::match(message.media.content, [&](const Photo &photo) { pushPhoto(photo.image); pushTTL(); }, [&](const Document &data) { diff --git a/Telegram/SourceFiles/export/output/export_output_text.cpp b/Telegram/SourceFiles/export/output/export_output_text.cpp index 8cab557e92..e839deda35 100644 --- a/Telegram/SourceFiles/export/output/export_output_text.cpp +++ b/Telegram/SourceFiles/export/output/export_output_text.cpp @@ -102,7 +102,7 @@ QByteArray SerializeMessage( const QString &internalLinksDomain) { using namespace Data; - if (message.media.content.is()) { + if (v::is(message.media.content)) { return "Error! This message is not supported " "by this version of Telegram Desktop. " "Please update the application."; @@ -219,7 +219,7 @@ QByteArray SerializeMessage( } }; - message.action.content.match([&](const ActionChatCreate &data) { + v::match(message.action.content, [&](const ActionChatCreate &data) { pushActor(); pushAction("Create group"); push("Title", data.title); @@ -340,7 +340,7 @@ QByteArray SerializeMessage( pushAction("Request Phone Number"); }, [](v::null_t) {}); - if (!message.action.content) { + if (v::is_null(message.action.content)) { pushFrom(); push("Author", message.signature); if (message.forwardedFromId) { @@ -357,7 +357,7 @@ QByteArray SerializeMessage( } } - message.media.content.match([&](const Photo &photo) { + v::match(message.media.content, [&](const Photo &photo) { pushPhoto(photo.image); pushTTL(); }, [&](const Document &data) { diff --git a/Telegram/SourceFiles/export/view/export_view_content.h b/Telegram/SourceFiles/export/view/export_view_content.h index 18500b7a45..7e22b8bec5 100644 --- a/Telegram/SourceFiles/export/view/export_view_content.h +++ b/Telegram/SourceFiles/export/view/export_view_content.h @@ -41,11 +41,11 @@ struct Content { return std::move( state ) | rpl::filter([](const State &state) { - return state.is() || state.is(); + return v::is(state) || v::is(state); }) | rpl::map([=](const State &state) { - if (const auto process = base::get_if(&state)) { + if (const auto process = std::get_if(&state)) { return ContentFromState(settings, *process); - } else if (const auto done = base::get_if(&state)) { + } else if (const auto done = std::get_if(&state)) { return ContentFromState(*done); } Unexpected("State type in ContentFromState."); diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index b91fa15d5c..667564f72a 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -306,7 +306,7 @@ void PanelController::showProgress() { progress->doneClicks( ) | rpl::start_with_next([=] { - if (const auto finished = base::get_if(&_state)) { + if (const auto finished = std::get_if(&_state)) { File::ShowInFolder(finished->path); LOG(("Export Info: Panel Hide By Done: %1." ).arg(finished->path)); @@ -319,7 +319,7 @@ void PanelController::showProgress() { } void PanelController::stopWithConfirmation(FnMut callback) { - if (!_state.is()) { + if (!v::is(_state)) { LOG(("Export Info: Stop Panel Without Confirmation.")); stopExport(); if (callback) { @@ -367,7 +367,7 @@ rpl::producer<> PanelController::stopRequests() const { return _panelCloseEvents.events( ) | rpl::flatten_latest( ) | rpl::filter([=] { - return !_state.is() || _stopRequested; + return !v::is(_state) || _stopRequested; }); } @@ -376,21 +376,21 @@ void PanelController::fillParams(const PasswordCheckState &state) { } void PanelController::updateState(State &&state) { - if (const auto start = base::get_if(&state)) { + if (const auto start = std::get_if(&state)) { fillParams(*start); } if (!_panel) { createPanel(); } _state = std::move(state); - if (const auto apiError = base::get_if(&_state)) { + if (const auto apiError = std::get_if(&_state)) { showError(*apiError); - } else if (const auto error = base::get_if(&_state)) { + } else if (const auto error = std::get_if(&_state)) { showError(*error); - } else if (_state.is()) { + } else if (v::is(_state)) { _panel->setTitle(tr::lng_export_title()); _panel->setHideOnDeactivate(false); - } else if (_state.is()) { + } else if (v::is(_state)) { LOG(("Export Info: Stop Panel After Cancel.")); stopExport(); } diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 23cbebcca7..12484caa5f 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -47,7 +47,7 @@ PeerData *Key::peer() const { } //Data::Feed *Key::feed() const { // #feed -// if (const auto feed = base::get_if>(&_value)) { +// if (const auto feed = std::get_if>(&_value)) { // return *feed; // } // return nullptr; diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp index c5cc65afe5..ab3126932b 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp @@ -62,7 +62,8 @@ private: Looped, Finished, }; - using ReadEnoughState = base::optional_variant< + using ReadEnoughState = std::variant< + v::null_t, FrameResult, Shared::PrepareNextCheck>; @@ -225,7 +226,7 @@ void VideoTrackObject::readFrames() { auto time = trackTime().trackTime; while (true) { const auto result = readEnoughFrames(time); - result.match([&](FrameResult result) { + v::match(result, [&](FrameResult result) { if (result == FrameResult::Done || result == FrameResult::Finished) { presentFrameIfNeeded(); @@ -241,7 +242,7 @@ void VideoTrackObject::readFrames() { } }, [](v::null_t) { }); - if (result.has_value()) { + if (!v::is_null(result)) { break; } } @@ -251,7 +252,7 @@ auto VideoTrackObject::readEnoughFrames(crl::time trackTime) -> ReadEnoughState { const auto dropStaleFrames = !_options.waitForMarkAsShown; const auto state = _shared->prepareState(trackTime, dropStaleFrames); - return state.match([&](Shared::PrepareFrame frame) -> ReadEnoughState { + return v::match(state, [&](Shared::PrepareFrame frame) -> ReadEnoughState { while (true) { const auto result = readFrame(frame); if (result != FrameResult::Done) { @@ -670,7 +671,7 @@ auto VideoTrack::Shared::prepareState( // If player already awaits next frame - we ignore if it's stale. dropStaleFrames = false; const auto result = prepareNext(index); - return result.is() ? PrepareState() : result; + return v::is(result) ? PrepareState() : result; }; switch (counter()) { diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h index a6525ac1c8..880bb0acc6 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h @@ -91,7 +91,8 @@ private: public: using PrepareFrame = not_null; using PrepareNextCheck = crl::time; - using PrepareState = base::optional_variant< + using PrepareState = std::variant< + v::null_t, PrepareFrame, PrepareNextCheck>; struct PresentFrame { diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 82fc4968af..4ee26c3aeb 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -39,7 +39,7 @@ using Key = GroupThumbs::Key; Data::FileOrigin ComputeFileOrigin(const Key &key, const Context &context) { return v::match(key, [&](PhotoId photoId) { - return context.match([&](PeerId peerId) { + return v::match(context, [&](PeerId peerId) { return peerIsUser(peerId) ? Data::FileOriginUserPhoto(peerToUser(peerId), photoId) : Data::FileOrigin(Data::FileOriginPeerPhoto(peerId)); @@ -49,7 +49,7 @@ Data::FileOrigin ComputeFileOrigin(const Key &key, const Context &context) { }, [](FullMsgId itemId) { return Data::FileOrigin(itemId); }, [&](GroupThumbs::CollageKey) { - return context.match([](const GroupThumbs::CollageSlice &slice) { + return v::match(context, [](const GroupThumbs::CollageSlice &slice) { return Data::FileOrigin(slice.context); }, [](auto&&) { return Data::FileOrigin(); @@ -442,7 +442,7 @@ void GroupThumbs::RefreshFromSlice( if (instance) { instance->updateContext(context); } - if (!context) { + if (v::is_null(context)) { if (instance) { instance->resizeToWidth(availableWidth); } @@ -579,7 +579,7 @@ auto GroupThumbs::createThumb(Key key) } return createThumb(key, nullptr); } else if (const auto collageKey = std::get_if(&key)) { - if (const auto itemId = base::get_if(&_context)) { + if (const auto itemId = std::get_if(&_context)) { if (const auto item = _session->data().message(*itemId)) { if (const auto media = item->media()) { if (const auto page = media->webpage()) { diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.h b/Telegram/SourceFiles/media/view/media_view_group_thumbs.h index 9a91b2b8ec..b425256cfc 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.h +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.h @@ -80,7 +80,8 @@ public: return _lifetime; } - using Context = base::optional_variant< + using Context = std::variant< + v::null_t, PeerId, MessageGroupId, FullMsgId>; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 18dd4b7596..9e922cee88 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1621,10 +1621,10 @@ Data::FileOrigin OverlayWidget::fileOrigin() const { Data::FileOrigin OverlayWidget::fileOrigin(const Entity &entity) const { if (const auto item = entity.item) { return item->fullId(); - } else if (!entity.data.is>()) { + } else if (!v::is>(entity.data)) { return Data::FileOrigin(); } - const auto photo = entity.data.get_unchecked>(); + const auto photo = std::get>(entity.data); if (_user) { return Data::FileOriginUserPhoto(_user->bareId(), photo->id); } else if (_peer && _peer->userpicPhotoId() == photo->id) { @@ -3605,16 +3605,17 @@ OverlayWidget::Entity OverlayWidget::entityByIndex(int index) const { } void OverlayWidget::setContext( - base::optional_variant< + std::variant< + v::null_t, not_null, not_null> context) { - if (const auto item = base::get_if>(&context)) { + if (const auto item = std::get_if>(&context)) { _msgid = (*item)->fullId(); _canForwardItem = (*item)->allowsForward(); _canDeleteItem = (*item)->canDelete(); _history = (*item)->history(); _peer = _history->peer; - } else if (const auto peer = base::get_if>(&context)) { + } else if (const auto peer = std::get_if>(&context)) { _msgid = FullMsgId(); _canForwardItem = _canDeleteItem = false; _history = (*peer)->owner().history(*peer); @@ -3681,7 +3682,7 @@ bool OverlayWidget::moveToNext(int delta) { } bool OverlayWidget::moveToEntity(const Entity &entity, int preloadDelta) { - if (!entity.data && !entity.item) { + if (v::is_null(entity.data) && !entity.item) { return false; } if (const auto item = entity.item) { @@ -3693,9 +3694,9 @@ bool OverlayWidget::moveToEntity(const Entity &entity, int preloadDelta) { } clearStreaming(); _streamingStartPaused = false; - if (auto photo = base::get_if>(&entity.data)) { + if (auto photo = std::get_if>(&entity.data)) { displayPhoto(*photo, entity.item); - } else if (auto document = base::get_if>(&entity.data)) { + } else if (auto document = std::get_if>(&entity.data)) { displayDocument(*document, entity.item); } else { displayDocument(nullptr, entity.item); @@ -3716,11 +3717,11 @@ void OverlayWidget::preloadData(int delta) { auto documents = base::flat_set>(); for (auto index = from; index != till + 1; ++index) { auto entity = entityByIndex(index); - if (auto photo = base::get_if>(&entity.data)) { + if (auto photo = std::get_if>(&entity.data)) { 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 = base::get_if>( + } else if (auto document = std::get_if>( &entity.data)) { const auto [i, ok] = documents.emplace( (*document)->createMediaView()); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index d10d6bfcf9..edcfae7055 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -153,7 +153,8 @@ private: OverVideo, }; struct Entity { - base::optional_variant< + std::variant< + v::null_t, not_null, not_null> data; HistoryItem *item; @@ -212,7 +213,8 @@ private: Entity entityByIndex(int index) const; Entity entityForItemId(const FullMsgId &itemId) const; bool moveToEntity(const Entity &entity, int preloadDelta = 0); - void setContext(base::optional_variant< + void setContext(std::variant< + v::null_t, not_null, not_null> context); diff --git a/Telegram/SourceFiles/passport/passport_encryption.h b/Telegram/SourceFiles/passport/passport_encryption.h index 69e0a62fd8..522e34f5a7 100644 --- a/Telegram/SourceFiles/passport/passport_encryption.h +++ b/Telegram/SourceFiles/passport/passport_encryption.h @@ -25,7 +25,7 @@ struct DataError { // QByteArray - bad existing scan with such file_hash // QString - bad data field value with such key // std::nullopt - additional scan required - base::optional_variant key; + std::variant key; QString type; // personal_details, passport, etc. QString text; diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 46a1a4b9c4..c0a928f402 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -866,7 +866,7 @@ void FormController::submitPassword( const auto &settings = wrapped->c_secureSecretSettings(); const auto algo = Core::ParseSecureSecretAlgo( settings.vsecure_algo()); - if (!algo) { + if (v::is_null(algo)) { _view->showUpdateAppBox(); return; } @@ -956,7 +956,7 @@ void FormController::checkSavedPasswordSettings( const auto &settings = wrapped->c_secureSecretSettings(); const auto algo = Core::ParseSecureSecretAlgo( settings.vsecure_algo()); - if (!algo) { + if (v::is_null(algo)) { _view->showUpdateAppBox(); return; } else if (!settings.vsecure_secret().v.isEmpty() @@ -2609,8 +2609,8 @@ void FormController::showForm() { return; } if (_password.unknownAlgo - || !_password.newAlgo - || !_password.newSecureAlgo) { + || v::is_null(_password.newAlgo) + || v::is_null(_password.newSecureAlgo)) { _view->showUpdateAppBox(); return; } else if (_password.request) { diff --git a/Telegram/SourceFiles/passport/passport_form_controller.h b/Telegram/SourceFiles/passport/passport_form_controller.h index 5afba1374d..8491cc4a95 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_controller.h @@ -287,9 +287,11 @@ struct PasswordSettings { // different random parts added on the client to the server salts. // && (newAlgo == other.newAlgo) // && (newSecureAlgo == other.newSecureAlgo) - && ((!newAlgo && !other.newAlgo) || (newAlgo && other.newAlgo)) - && ((!newSecureAlgo && !other.newSecureAlgo) - || (newSecureAlgo && other.newSecureAlgo)) + && ((v::is_null(newAlgo) && v::is_null(other.newAlgo)) + || (!v::is_null(newAlgo) && !v::is_null(other.newAlgo))) + && ((v::is_null(newSecureAlgo) && v::is_null(other.newSecureAlgo)) + || (!v::is_null(newSecureAlgo) + && !v::is_null(other.newSecureAlgo))) && (hint == other.hint) && (unconfirmedPattern == other.unconfirmedPattern) && (confirmedEmail == other.confirmedEmail) diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index faa95de325..35ff2ea64e 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -676,8 +676,8 @@ void PanelController::setupPassword() { const auto &settings = _form->passwordSettings(); if (settings.unknownAlgo - || !settings.newAlgo - || !settings.newSecureAlgo) { + || v::is_null(settings.newAlgo) + || v::is_null(settings.newSecureAlgo)) { showUpdateAppBox(); return; } else if (settings.request) { diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index e1f937bbd5..f04f49af1d 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -583,8 +583,8 @@ bool CheckEditCloudPassword(not_null<::Main::Session*> session) { Assert(current.has_value()); if (!current->unknownAlgorithm - && current->newPassword - && current->newSecureSecret) { + && !v::is_null(current->newPassword) + && !v::is_null(current->newSecureSecret)) { return true; } return false; diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 706f350093..09f7146ac6 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -717,7 +717,7 @@ void FileLoadTask::process() { _information = readMediaInformation(Core::MimeTypeForFile(info).name()); } filemime = _information->filemime; - if (auto image = base::get_if( + if (auto image = std::get_if( &_information->media)) { fullimage = base::take(image->data); if (!Core::IsMimeSticker(filemime)) { @@ -732,7 +732,7 @@ void FileLoadTask::process() { filemime = "audio/ogg"; } else { if (_information) { - if (auto image = base::get_if( + if (auto image = std::get_if( &_information->media)) { fullimage = base::take(image->data); } @@ -757,7 +757,7 @@ void FileLoadTask::process() { } } else { if (_information) { - if (auto image = base::get_if( + if (auto image = std::get_if( &_information->media)) { fullimage = base::take(image->data); } @@ -807,13 +807,13 @@ void FileLoadTask::process() { _information = readMediaInformation(filemime); filemime = _information->filemime; } - if (auto song = base::get_if( + if (auto song = std::get_if( &_information->media)) { isSong = true; auto flags = MTPDdocumentAttributeAudio::Flag::f_title | MTPDdocumentAttributeAudio::Flag::f_performer; attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(song->duration), MTP_string(song->title), MTP_string(song->performer), MTPstring())); thumbnail = PrepareFileThumbnail(std::move(song->cover)); - } else if (auto video = base::get_if( + } else if (auto video = std::get_if( &_information->media)) { isVideo = true; auto coverWidth = video->thumbnail.width(); diff --git a/Telegram/SourceFiles/storage/localimageloader.h b/Telegram/SourceFiles/storage/localimageloader.h index b7a40711de..fed9e2a9d0 100644 --- a/Telegram/SourceFiles/storage/localimageloader.h +++ b/Telegram/SourceFiles/storage/localimageloader.h @@ -258,7 +258,7 @@ struct FileMediaInformation { }; QString filemime; - base::optional_variant media; + std::variant media; }; class FileLoadTask final : public Task { diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index d8ff217849..c67f36b347 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -83,7 +83,7 @@ bool PrepareAlbumMediaIsWaiting( using Image = FileMediaInformation::Image; using Video = FileMediaInformation::Video; - if (const auto image = base::get_if( + if (const auto image = std::get_if( &file.information->media)) { if (ValidPhotoForAlbum(*image, file.mime)) { file.shownDimensions = PrepareShownDimensions(image->data); @@ -95,7 +95,7 @@ bool PrepareAlbumMediaIsWaiting( file.preview.setDevicePixelRatio(cRetinaFactor()); file.type = PreparedFile::AlbumType::Photo; } - } else if (const auto video = base::get_if