Replace mapbox variant with std::variant.

This commit is contained in:
John Preston 2020-08-31 12:14:53 +04:00
parent b3eb41b989
commit 734d834a20
58 changed files with 207 additions and 194 deletions

View File

@ -2684,14 +2684,14 @@ void ApiWrap::requestFileReference(
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87122
const auto &origin = p.first;
const auto &reference = p.second;
const auto documentId = base::get_if<DocumentFileLocationId>(
const auto documentId = std::get_if<DocumentFileLocationId>(
&origin);
if (documentId) {
_session->data().document(
documentId->id
)->refreshFileReference(reference);
}
const auto photoId = base::get_if<PhotoFileLocationId>(&origin);
const auto photoId = std::get_if<PhotoFileLocationId>(&origin);
if (photoId) {
_session->data().photo(
photoId->id
@ -2826,7 +2826,7 @@ void ApiWrap::refreshFileReference(
MTP_long(data.themeId),
MTP_long(data.accessHash)),
MTP_long(0)));
}, [&](std::nullopt_t) {
}, [&](v::null_t) {
fail();
});
}

View File

@ -446,7 +446,7 @@ int BackgroundBox::Inner::getSelectionIndex(
return data.index;
}, [](const DeleteSelected &data) {
return data.index;
}, [](std::nullopt_t) {
}, [](v::null_t) {
return -1;
});
}

View File

@ -225,7 +225,7 @@ auto AddButtonWithLoader(
buttonState->value(
) | rpl::start_with_next([=](const DictState &state) {
const auto isToggledSet = state.is<Active>();
const auto isToggledSet = v::is<Active>(state);
const auto toggled = isToggledSet ? 1. : 0.;
const auto over = !button->isDisabled()
&& (button->isDown() || button->isOver());
@ -252,7 +252,7 @@ auto AddButtonWithLoader(
dictionaryRemoved->events(),
buttonState->value(
) | rpl::filter([](const DictState &state) {
return state.is<Failed>();
return v::is<Failed>(state);
}) | rpl::to_empty
) | rpl::map_to(false)
)
@ -276,13 +276,14 @@ auto AddButtonWithLoader(
});
}) | rpl::flatten_latest(
) | rpl::filter([=](const DictState &state) {
return !buttonState->current().is<Failed>() || !state.is<Available>();
return !v::is<Failed>(buttonState->current())
|| !v::is<Available>(state);
});
button->toggledValue(
) | rpl::start_with_next([=](bool toggled) {
const auto &state = buttonState->current();
if (toggled && (state.is<Available>() || state.is<Failed>())) {
if (toggled && (v::is<Available>(state) || v::is<Failed>(state))) {
const auto weak = Ui::MakeWeak(button);
setLocalLoader(base::make_unique_q<Loader>(
QCoreApplication::instance(),
@ -292,7 +293,7 @@ auto AddButtonWithLoader(
Spellchecker::DictPathByLangId(id),
Spellchecker::GetDownloadSize(id),
crl::guard(weak, destroyLocalLoader)));
} else if (!toggled && state.is<Loading>()) {
} else if (!toggled && v::is<Loading>(state)) {
if (const auto g = rawGlobalLoaderPtr()) {
g->destroy();
return;

View File

@ -431,7 +431,7 @@ void EditCaptionBox::setupStreamedPreview(std::shared_ptr<Document> shared) {
}
void EditCaptionBox::handleStreamingUpdate(Update &&update) {
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
streamingReady(std::move(update));
}, [&](const PreloadedVideo &update) {
}, [&](const UpdateVideo &update) {

View File

@ -395,7 +395,7 @@ void Rows::mouseReleaseEvent(QMouseEvent *e) {
activateByIndex(data.index);
}, [&](MenuSelection data) {
showMenu(data.index);
}, [](std::nullopt_t) {});
}, [](v::null_t) {});
}
}
@ -601,7 +601,7 @@ int Rows::indexFromSelection(Selection selected) const {
return data.index;
}, [&](MenuSelection data) {
return data.index;
}, [](std::nullopt_t) {
}, [](v::null_t) {
return -1;
});
}
@ -648,7 +648,7 @@ rpl::producer<bool> Rows::isEmpty() const {
}
void Rows::repaint(Selection selected) {
selected.match([](std::nullopt_t) {
selected.match([](v::null_t) {
}, [&](const auto &data) {
repaint(data.index);
});

View File

@ -263,8 +263,8 @@ void Row::paintRadio(Painter &p) {
const auto loading = _loading
? _loading->computeState()
: Ui::RadialState{ 0., 0, FullArcLength };
const auto isToggledSet = _state.current().is<Active>();
const auto isActiveSet = isToggledSet || _state.current().is<Loading>();
const auto isToggledSet = v::is<Active>(_state.current());
const auto isActiveSet = isToggledSet || v::is<Loading>(_state.current());
const auto toggled = _toggled.value(isToggledSet ? 1. : 0.);
const auto active = _active.value(isActiveSet ? 1. : 0.);
const auto _st = &st::defaultRadio;
@ -345,7 +345,7 @@ void Row::onStateChanged(State was, StateChangeSource source) {
}
void Row::updateStatusColorOverride() {
const auto isToggledSet = _state.current().is<Active>();
const auto isToggledSet = v::is<Active>(_state.current());
const auto toggled = _toggled.value(isToggledSet ? 1. : 0.);
const auto over = showOver();
if (toggled == 0. && !over) {
@ -373,7 +373,8 @@ void Row::setupContent(const Set &set) {
});
}) | rpl::flatten_latest(
) | rpl::filter([=](const SetState &state) {
return !_state.current().is<Failed>() || !state.is<Available>();
return !v::is<Failed>(_state.current())
|| !v::is<Available>(state);
});
setupLabels(set);
@ -390,9 +391,10 @@ void Row::setupHandler() {
clicks(
) | rpl::filter([=] {
const auto &state = _state.current();
return !_switching && (state.is<Ready>() || state.is<Available>());
return !_switching && (v::is<Ready>(state)
|| v::is<Available>(state));
}) | rpl::start_with_next([=] {
if (_state.current().is<Available>()) {
if (v::is<Available>(_state.current())) {
load();
return;
}
@ -409,7 +411,7 @@ void Row::setupHandler() {
_state.value(
) | rpl::map([=](const SetState &state) {
return state.is<Ready>() || state.is<Available>();
return v::is<Ready>(state) || v::is<Available>(state);
}) | rpl::start_with_next([=](bool active) {
setDisabled(!active);
setPointerCursor(active);
@ -463,7 +465,7 @@ void Row::setupPreview(const Set &set) {
void Row::updateLoadingToFinished() {
_loading->update(
_state.current().is<Failed>() ? 0. : 1.,
v::is<Failed>(_state.current()) ? 0. : 1.,
true,
crl::now());
}
@ -471,7 +473,7 @@ void Row::updateLoadingToFinished() {
void Row::radialAnimationCallback(crl::time now) {
const auto updated = [&] {
const auto state = _state.current();
if (const auto loading = base::get_if<Loading>(&state)) {
if (const auto loading = std::get_if<Loading>(&state)) {
return _loading->update(CountProgress(loading), false, now);
} else {
updateLoadingToFinished();
@ -493,7 +495,7 @@ void Row::setupAnimation() {
_state.value(
) | rpl::map(
_1 == Active()
_1 == SetState{ Active() }
) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](bool toggled) {
_toggled.start(
@ -505,7 +507,7 @@ void Row::setupAnimation() {
_state.value(
) | rpl::map([](const SetState &state) {
return state.is<Loading>() || state.is<Active>();
return v::is<Loading>(state) || v::is<Active>(state);
}) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](bool active) {
_active.start(
@ -517,7 +519,7 @@ void Row::setupAnimation() {
_state.value(
) | rpl::map([](const SetState &state) {
return base::get_if<Loading>(&state);
return std::get_if<Loading>(&state);
}) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](const Loading *loading) {
if (loading && !_loading) {

View File

@ -143,7 +143,7 @@ private:
Search,
Settings,
};
using OverState = base::variant<SpecialOver, int>;
using OverState = std::variant<SpecialOver, int>;
template <typename Callback>
void enumerateVisibleIcons(Callback callback);
@ -548,7 +548,7 @@ void StickersListWidget::Footer::mouseMoveEvent(QMouseEvent *e) {
if (!_iconsDragging
&& !_icons.empty()
&& base::get_if<int>(&_iconDown) != nullptr) {
&& v::is<int>(_iconDown)) {
if ((_iconsMousePos - _iconsMouseDown).manhattanLength() >= QApplication::startDragDistance()) {
_iconsDragging = true;
}
@ -579,7 +579,7 @@ void StickersListWidget::Footer::mouseReleaseEvent(QMouseEvent *e) {
updateSelected();
if (wasDown == _iconOver) {
if (const auto index = base::get_if<int>(&_iconOver)) {
if (const auto index = std::get_if<int>(&_iconOver)) {
_iconSelX = anim::value(
*index * st::stickerIconWidth,
*index * st::stickerIconWidth);
@ -604,7 +604,7 @@ bool StickersListWidget::Footer::eventHook(QEvent *e) {
if (e->type() == QEvent::TouchBegin) {
} else if (e->type() == QEvent::Wheel) {
if (!_icons.empty()
&& (base::get_if<int>(&_iconOver) != nullptr)
&& v::is<int>(_iconOver)
&& (_iconDown == SpecialOver::None)) {
scrollByWheelEvent(static_cast<QWheelEvent*>(e));
}
@ -635,7 +635,7 @@ void StickersListWidget::Footer::scrollByWheelEvent(
}
void StickersListWidget::Footer::updateSelected() {
if (_iconDown >= 0) {
if (_iconDown != SpecialOver::None) {
return;
}
@ -2109,7 +2109,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
_previewTimer.cancel();
auto pressed = _pressed;
setPressed(std::nullopt);
setPressed(v::null);
if (pressed != _selected) {
update();
}
@ -2271,8 +2271,8 @@ void StickersListWidget::enterFromChildEvent(QEvent *e, QWidget *child) {
}
void StickersListWidget::clearSelection() {
setPressed(std::nullopt);
setSelected(std::nullopt);
setPressed(v::null);
setSelected(v::null);
update();
}
@ -2754,7 +2754,7 @@ void StickersListWidget::updateSelected() {
return;
}
auto newSelected = OverState { std::nullopt };
auto newSelected = OverState { v::null };
auto p = mapFromGlobal(_lastMousePosition);
if (!rect().contains(p)
|| p.y() < getVisibleTop() || p.y() >= getVisibleBottom()

View File

@ -157,7 +157,7 @@ CloudPasswordResult ComputeCheck(
}
bytes::vector ComputeHash(
std::nullopt_t,
v::null_t,
bytes::const_span password) {
Unexpected("Bad secure secret algorithm.");
}
@ -200,7 +200,7 @@ CloudPasswordCheckRequest ParseCloudPasswordCheckRequest(
CloudPasswordAlgo ValidateNewCloudPasswordAlgo(CloudPasswordAlgo &&parsed) {
if (!parsed.is<CloudPasswordAlgoModPow>()) {
return std::nullopt;
return v::null;
}
auto &value = parsed.get_unchecked<CloudPasswordAlgoModPow>();
const auto already = value.salt1.size();
@ -216,7 +216,7 @@ MTPPasswordKdfAlgo PrepareCloudPasswordAlgo(const CloudPasswordAlgo &data) {
MTP_bytes(data.salt2),
MTP_int(data.g),
MTP_bytes(data.p));
}, [](std::nullopt_t) {
}, [](v::null_t) {
return MTP_passwordKdfAlgoUnknown();
});
}
@ -230,7 +230,7 @@ bytes::vector ComputeCloudPasswordHash(
bytes::const_span password) {
return algo.match([&](const CloudPasswordAlgoModPow &data) {
return ComputeHash(data, password);
}, [](std::nullopt_t) -> bytes::vector {
}, [](v::null_t) -> bytes::vector {
Unexpected("Bad cloud password algorithm.");
});
}
@ -240,7 +240,7 @@ CloudPasswordDigest ComputeCloudPasswordDigest(
bytes::const_span password) {
return algo.match([&](const CloudPasswordAlgoModPow &data) {
return ComputeDigest(data, password);
}, [](std::nullopt_t) -> CloudPasswordDigest {
}, [](v::null_t) -> CloudPasswordDigest {
Unexpected("Bad cloud password algorithm.");
});
}
@ -250,7 +250,7 @@ CloudPasswordResult ComputeCloudPasswordCheck(
bytes::const_span hash) {
return request.algo.match([&](const CloudPasswordAlgoModPow &data) {
return ComputeCheck(request, data, hash);
}, [](std::nullopt_t) -> CloudPasswordResult {
}, [](v::null_t) -> CloudPasswordResult {
Unexpected("Bad cloud password algorithm.");
});
}
@ -271,7 +271,7 @@ SecureSecretAlgo ParseSecureSecretAlgo(
SecureSecretAlgo ValidateNewSecureSecretAlgo(SecureSecretAlgo &&parsed) {
if (!parsed.is<SecureSecretAlgoPBKDF2>()) {
return std::nullopt;
return v::null;
}
auto &value = parsed.get_unchecked<SecureSecretAlgoPBKDF2>();
const auto already = value.salt.size();
@ -287,7 +287,7 @@ MTPSecurePasswordKdfAlgo PrepareSecureSecretAlgo(
MTP_bytes(data.salt));
}, [](const SecureSecretAlgoSHA512 &data) {
return MTP_securePasswordKdfAlgoSHA512(MTP_bytes(data.salt));
}, [](std::nullopt_t) {
}, [](v::null_t) {
return MTP_securePasswordKdfAlgoUnknown();
});
}

View File

@ -35,7 +35,7 @@ enum Status {
Started
};
// Open status or crash report dump.
using StartResult = base::variant<Status, QByteArray>;
using StartResult = std::variant<Status, QByteArray>;
StartResult Start();
Status Restart(); // can be only CantOpen or Started
void Finish();

View File

@ -315,7 +315,7 @@ void Sandbox::singleInstanceChecked() {
return;
}
const auto result = CrashReports::Start();
result.match([&](CrashReports::Status status) {
v::match(result, [&](CrashReports::Status status) {
if (status == CrashReports::CantOpen) {
new NotStartedWindow();
} else {

View File

@ -54,7 +54,7 @@ void CloudImage::set(
_file.flags = CloudFile::Flag();
_view = std::weak_ptr<CloudImageView>();
} else if (was != now
&& (!was.is<InMemoryLocation>() || now.is<InMemoryLocation>())) {
&& (!v::is<InMemoryLocation>(was) || v::is<InMemoryLocation>(now))) {
_file.location = ImageLocation();
_view = std::weak_ptr<CloudImageView>();
}
@ -176,8 +176,8 @@ void UpdateCloudFile(
}
auto cacheBytes = !data.bytes.isEmpty()
? data.bytes
: file.location.file().data.is<InMemoryLocation>()
? file.location.file().data.get_unchecked<InMemoryLocation>().bytes
: v::is<InMemoryLocation>(file.location.file().data)
? std::get<InMemoryLocation>(file.location.file().data).bytes
: QByteArray();
if (!cacheBytes.isEmpty()) {
if (const auto cacheKey = data.location.file().cacheKey()) {

View File

@ -148,7 +148,7 @@ inline bool operator<(PhotoFileLocationId a, PhotoFileLocationId b) {
return a.id < b.id;
}
using FileLocationId = base::variant<
using FileLocationId = std::variant<
DocumentFileLocationId,
PhotoFileLocationId>;

View File

@ -445,10 +445,10 @@ auto PhotoData::createStreamingLoader(
return Media::Streaming::MakeBytesLoader(media->videoContent());
}
}
return videoLocation().file().data.is<StorageFileLocation>()
return v::is<StorageFileLocation>(videoLocation().file().data)
? std::make_unique<Media::Streaming::LoaderMtproto>(
&session().downloader(),
videoLocation().file().data.get_unchecked<StorageFileLocation>(),
std::get<StorageFileLocation>(videoLocation().file().data),
videoByteSize(),
origin)
: nullptr;

View File

@ -231,11 +231,11 @@ std::optional<int> SharedMediaWithLastSlice::skippedAfter() const {
}
std::optional<int> SharedMediaWithLastSlice::indexOfImpl(Value value) const {
return base::get_if<FullMsgId>(&value)
? _slice.indexOf(*base::get_if<FullMsgId>(&value))
return std::get_if<FullMsgId>(&value)
? _slice.indexOf(*std::get_if<FullMsgId>(&value))
: (isolatedInSlice()
|| !_lastPhotoId
|| (*base::get_if<not_null<PhotoData*>>(&value))->id != *_lastPhotoId)
|| (*std::get_if<not_null<PhotoData*>>(&value))->id != *_lastPhotoId)
? std::nullopt
: Add(_slice.size() - 1, lastPhotoSkip());
}
@ -267,14 +267,14 @@ std::optional<int> SharedMediaWithLastSlice::indexOf(Value value) const {
info.push_back((_ending && _ending->skippedAfter())
? QString::number(*_ending->skippedAfter())
: QString("-"));
if (const auto msgId = base::get_if<FullMsgId>(&value)) {
if (const auto msgId = std::get_if<FullMsgId>(&value)) {
info.push_back("value:" + QString::number(msgId->channel));
info.push_back(QString::number(msgId->msg));
const auto index = _slice.indexOf(*base::get_if<FullMsgId>(&value));
const auto index = _slice.indexOf(*std::get_if<FullMsgId>(&value));
info.push_back("index:" + (index
? QString::number(*index)
: QString("-")));
} else if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
} else if (const auto photo = std::get_if<not_null<PhotoData*>>(&value)) {
info.push_back("value:" + QString::number((*photo)->id));
} else {
info.push_back("value:bad");
@ -373,7 +373,7 @@ rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
int limitBefore,
int limitAfter) {
return [=](auto consumer) {
if (base::get_if<not_null<PhotoData*>>(&key.universalId)) {
if (std::get_if<not_null<PhotoData*>>(&key.universalId)) {
return SharedMediaMergedViewer(
session,
SharedMediaMergedKey(

View File

@ -60,9 +60,9 @@ class SharedMediaWithLastSlice {
public:
using Type = Storage::SharedMediaType;
using Value = base::variant<FullMsgId, not_null<PhotoData*>>;
using Value = std::variant<FullMsgId, not_null<PhotoData*>>;
using MessageId = SparseIdsMergedSlice::UniversalMsgId;
using UniversalMsgId = base::variant<
using UniversalMsgId = std::variant<
MessageId,
not_null<PhotoData*>>;
@ -76,8 +76,7 @@ public:
, migratedPeerId(migratedPeerId)
, type(type)
, universalId(universalId) {
Expects(base::get_if<MessageId>(&universalId) != nullptr
|| type == Type::ChatPhoto);
Expects(v::is<MessageId>(universalId) || type == Type::ChatPhoto);
}
bool operator==(const Key &other) const {
@ -120,8 +119,8 @@ public:
return {
key.peerId,
key.migratedPeerId,
base::get_if<MessageId>(&key.universalId)
? (*base::get_if<MessageId>(&key.universalId))
v::is<MessageId>(key.universalId)
? std::get<MessageId>(key.universalId)
: ServerMaxMsgId - 1
};
}
@ -135,7 +134,7 @@ public:
private:
static std::optional<SparseIdsMergedSlice> EndingSlice(const Key &key) {
return base::get_if<MessageId>(&key.universalId)
return v::is<MessageId>(key.universalId)
? base::make_optional(SparseIdsMergedSlice(EndingKey(key)))
: std::nullopt;
}
@ -161,12 +160,12 @@ private:
msgId);
}
static Value ComputeId(const Key &key) {
if (auto messageId = base::get_if<MessageId>(&key.universalId)) {
if (const auto messageId = std::get_if<MessageId>(&key.universalId)) {
return (*messageId >= 0)
? ComputeId(key.peerId, *messageId)
: ComputeId(key.migratedPeerId, ServerMaxMsgId + *messageId);
}
return *base::get_if<not_null<PhotoData*>>(&key.universalId);
return std::get<not_null<PhotoData*>>(key.universalId);
}
bool isolatedInSlice() const {

View File

@ -29,7 +29,7 @@ enum class WebPageType {
WebPageType ParseWebPageType(const MTPDwebPage &type);
struct WebPageCollage {
using Item = base::variant<PhotoData*, DocumentData*>;
using Item = std::variant<PhotoData*, DocumentData*>;
WebPageCollage() = default;
explicit WebPageCollage(

View File

@ -786,10 +786,10 @@ Utf8String User::name() const {
}
const User *Peer::user() const {
return base::get_if<User>(&data);
return std::get_if<User>(&data);
}
const Chat *Peer::chat() const {
return base::get_if<Chat>(&data);
return std::get_if<Chat>(&data);
}
PeerId Peer::id() const {

View File

@ -240,7 +240,7 @@ struct Peer {
const User *user() const;
const Chat *chat() const;
base::variant<User, Chat> data;
std::variant<User, Chat> data;
};

View File

@ -1090,7 +1090,7 @@ auto HtmlWriter::Wrap::pushMessage(
return serviceFrom + " joined Telegram";
}, [&](const ActionPhoneNumberRequest &data) {
return serviceFrom + " requested your phone number";
}, [](std::nullopt_t) { return QByteArray(); });
}, [](v::null_t) { return QByteArray(); });
if (!serviceText.isEmpty()) {
const auto &content = message.action.content;
@ -1753,7 +1753,7 @@ MediaData HtmlWriter::Wrap::prepareMediaData(
}, [](const Poll &data) {
}, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message.");
}, [](std::nullopt_t) {});
}, [](v::null_t) {});
return result;
}

View File

@ -471,7 +471,7 @@ QByteArray SerializeMessage(
}, [&](const ActionPhoneNumberRequest &data) {
pushActor();
pushAction("requested_phone_number");
}, [](std::nullopt_t) {});
}, [](v::null_t) {});
if (!message.action.content) {
pushFrom();
@ -612,7 +612,7 @@ QByteArray SerializeMessage(
}));
}, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message.");
}, [](std::nullopt_t) {});
}, [](v::null_t) {});
pushBare("text", SerializeText(context, message.text));

View File

@ -338,7 +338,7 @@ QByteArray SerializeMessage(
}, [&](const ActionPhoneNumberRequest &data) {
pushActor();
pushAction("Request Phone Number");
}, [](std::nullopt_t) {});
}, [](v::null_t) {});
if (!message.action.content) {
pushFrom();
@ -456,7 +456,7 @@ QByteArray SerializeMessage(
}
}, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message.");
}, [](std::nullopt_t) {});
}, [](v::null_t) {});
auto value = JoinList(QByteArray(), ranges::view::all(
message.text

View File

@ -1444,7 +1444,7 @@ void Gif::setStreamed(std::unique_ptr<Streamed> value) {
void Gif::handleStreamingUpdate(::Media::Streaming::Update &&update) {
using namespace ::Media::Streaming;
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
streamingReady(std::move(update));
}, [&](const PreloadedVideo &update) {
}, [&](const UpdateVideo &update) {

View File

@ -704,7 +704,7 @@ void Photo::setStreamed(std::unique_ptr<Streamed> value) {
void Photo::handleStreamingUpdate(::Media::Streaming::Update &&update) {
using namespace ::Media::Streaming;
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
streamingReady(std::move(update));
}, [&](const PreloadedVideo &update) {
}, [&](const UpdateVideo &update) {

View File

@ -313,7 +313,7 @@ void Sticker::lottieCreated() {
_lottie->updates(
) | rpl::start_with_next([=](Lottie::Update update) {
update.data.match([&](const Lottie::Information &information) {
v::match(update.data, [&](const Lottie::Information &information) {
_parent->history()->owner().requestViewResize(_parent);
}, [&](const Lottie::DisplayFrameRequest &request) {
_parent->history()->owner().requestViewRepaint(_parent);

View File

@ -53,11 +53,11 @@ std::vector<std::unique_ptr<Data::Media>> PrepareCollageMedia(
auto result = std::vector<std::unique_ptr<Data::Media>>();
result.reserve(data.items.size());
for (const auto item : data.items) {
if (const auto document = base::get_if<DocumentData*>(&item)) {
if (const auto document = std::get_if<DocumentData*>(&item)) {
result.push_back(std::make_unique<Data::MediaFile>(
parent,
*document));
} else if (const auto photo = base::get_if<PhotoData*>(&item)) {
} else if (const auto photo = std::get_if<PhotoData*>(&item)) {
result.push_back(std::make_unique<Data::MediaPhoto>(
parent,
*photo));

View File

@ -40,7 +40,7 @@ Key::Key(not_null<PollData*> poll, FullMsgId contextId)
}
PeerData *Key::peer() const {
if (const auto peer = base::get_if<not_null<PeerData*>>(&_value)) {
if (const auto peer = std::get_if<not_null<PeerData*>>(&_value)) {
return *peer;
}
return nullptr;
@ -54,21 +54,21 @@ PeerData *Key::peer() const {
//}
UserData *Key::settingsSelf() const {
if (const auto tag = base::get_if<Settings::Tag>(&_value)) {
if (const auto tag = std::get_if<Settings::Tag>(&_value)) {
return tag->self;
}
return nullptr;
}
PollData *Key::poll() const {
if (const auto data = base::get_if<PollKey>(&_value)) {
if (const auto data = std::get_if<PollKey>(&_value)) {
return data->poll;
}
return nullptr;
}
FullMsgId Key::pollContextId() const {
if (const auto data = base::get_if<PollKey>(&_value)) {
if (const auto data = std::get_if<PollKey>(&_value)) {
return data->contextId;
}
return FullMsgId();

View File

@ -46,7 +46,7 @@ private:
not_null<PollData*> poll;
FullMsgId contextId;
};
base::variant<
std::variant<
not_null<PeerData*>,
//not_null<Data::Feed*>, // #feed
Settings::Tag,

View File

@ -758,7 +758,7 @@ void Instance::handleStreamingUpdate(
Streaming::Update &&update) {
using namespace Streaming;
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
if (!update.video.size.isEmpty()) {
data->streamed->progress.setValueChangedCallback([=](
float64,

View File

@ -96,7 +96,7 @@ struct Finished {
};
struct Update {
base::variant<
std::variant<
Information,
PreloadedVideo,
UpdateVideo,

View File

@ -138,7 +138,7 @@ Ui::RadialState Document::waitingState() const {
}
void Document::handleUpdate(Update &&update) {
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
ready(std::move(update));
}, [&](const PreloadedVideo &update) {
_info.video.state.receivedTill = update.till;

View File

@ -228,7 +228,7 @@ void File::Context::seekToPosition(
return logFatal(qstr("av_seek_frame"), error);
}
base::variant<FFmpeg::Packet, FFmpeg::AvErrorWrap> File::Context::readPacket() {
std::variant<FFmpeg::Packet, FFmpeg::AvErrorWrap> File::Context::readPacket() {
auto error = FFmpeg::AvErrorWrap();
auto result = FFmpeg::Packet();
@ -312,7 +312,7 @@ void File::Context::readNextPacket() {
auto result = readPacket();
if (unroll()) {
return;
} else if (const auto packet = base::get_if<FFmpeg::Packet>(&result)) {
} else if (const auto packet = std::get_if<FFmpeg::Packet>(&result)) {
const auto index = packet->fields().stream_index;
const auto i = _queuedPackets.find(index);
if (i == end(_queuedPackets)) {
@ -325,8 +325,8 @@ void File::Context::readNextPacket() {
Assert(i->second.size() < kMaxQueuedPackets);
} else {
// Still trying to read by drain.
Assert(result.is<FFmpeg::AvErrorWrap>());
Assert(result.get<FFmpeg::AvErrorWrap>().code() == AVERROR_EOF);
Assert(v::is<FFmpeg::AvErrorWrap>(result));
Assert(std::get<FFmpeg::AvErrorWrap>(result).code() == AVERROR_EOF);
processQueuedPackets(SleepPolicy::Allowed);
if (!finished()) {
handleEndOfFile();

View File

@ -82,7 +82,7 @@ private:
// TODO base::expected.
[[nodiscard]] auto readPacket()
-> base::variant<FFmpeg::Packet, FFmpeg::AvErrorWrap>;
-> std::variant<FFmpeg::Packet, FFmpeg::AvErrorWrap>;
void processQueuedPackets(SleepPolicy policy);
void handleEndOfFile();

View File

@ -31,7 +31,9 @@ LoaderMtproto::LoaderMtproto(
}
Storage::Cache::Key LoaderMtproto::baseCacheKey() const {
return location().data.get<StorageFileLocation>().bigFileBaseCacheKey();
return std::get<StorageFileLocation>(
location().data
).bigFileBaseCacheKey();
}
int LoaderMtproto::size() const {

View File

@ -239,7 +239,7 @@ void VideoTrackObject::readFrames() {
if (delay != kTimeUnknown) {
queueReadFrames(delay);
}
}, [](std::nullopt_t) {
}, [](v::null_t) {
});
if (result.has_value()) {
break;
@ -258,12 +258,12 @@ auto VideoTrackObject::readEnoughFrames(crl::time trackTime)
return result;
} else if (!dropStaleFrames
|| !VideoTrack::IsStale(frame, trackTime)) {
return std::nullopt;
return v::null;
}
}
}, [&](Shared::PrepareNextCheck delay) -> ReadEnoughState {
return delay;
}, [&](std::nullopt_t) -> ReadEnoughState {
}, [&](v::null_t) -> ReadEnoughState {
return FrameResult::Done;
});
}

View File

@ -38,7 +38,7 @@ using Context = GroupThumbs::Context;
using Key = GroupThumbs::Key;
Data::FileOrigin ComputeFileOrigin(const Key &key, const Context &context) {
return key.match([&](PhotoId photoId) {
return v::match(key, [&](PhotoId photoId) {
return context.match([&](PeerId peerId) {
return peerIsUser(peerId)
? Data::FileOriginUserPhoto(peerToUser(peerId), photoId)
@ -64,12 +64,12 @@ Context ComputeContext(
Expects(index >= 0 && index < slice.size());
const auto value = slice[index];
if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
if (const auto photo = std::get_if<not_null<PhotoData*>>(&value)) {
if (const auto peer = (*photo)->peer) {
return peer->id;
}
return std::nullopt;
} else if (const auto msgId = base::get_if<FullMsgId>(&value)) {
return v::null;
} else if (const auto msgId = std::get_if<FullMsgId>(&value)) {
if (const auto item = session->data().message(*msgId)) {
if (!item->toHistoryMessage()) {
return item->history()->peer->id;
@ -77,7 +77,7 @@ Context ComputeContext(
return groupId;
}
}
return std::nullopt;
return v::null;
}
Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)");
}
@ -100,9 +100,9 @@ Key ComputeKey(const SharedMediaWithLastSlice &slice, int index) {
Expects(index >= 0 && index < slice.size());
const auto value = slice[index];
if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
if (const auto photo = std::get_if<not_null<PhotoData*>>(&value)) {
return (*photo)->id;
} else if (const auto msgId = base::get_if<FullMsgId>(&value)) {
} else if (const auto msgId = std::get_if<FullMsgId>(&value)) {
return *msgId;
}
Unexpected("Variant in ComputeKey(SharedMediaWithLastSlice::Value)");
@ -564,10 +564,10 @@ void GroupThumbs::animatePreviouslyAlive(
auto GroupThumbs::createThumb(Key key)
-> std::unique_ptr<Thumb> {
if (const auto photoId = base::get_if<PhotoId>(&key)) {
if (const auto photoId = std::get_if<PhotoId>(&key)) {
const auto photo = _session->data().photo(*photoId);
return createThumb(key, photo);
} else if (const auto msgId = base::get_if<FullMsgId>(&key)) {
} else if (const auto msgId = std::get_if<FullMsgId>(&key)) {
if (const auto item = _session->data().message(*msgId)) {
if (const auto media = item->media()) {
if (const auto photo = media->photo()) {
@ -578,7 +578,7 @@ auto GroupThumbs::createThumb(Key key)
}
}
return createThumb(key, nullptr);
} else if (const auto collageKey = base::get_if<CollageKey>(&key)) {
} else if (const auto collageKey = std::get_if<CollageKey>(&key)) {
if (const auto itemId = base::get_if<FullMsgId>(&_context)) {
if (const auto item = _session->data().message(*itemId)) {
if (const auto media = item->media()) {
@ -605,9 +605,9 @@ auto GroupThumbs::createThumb(
return createThumb(key, nullptr);
}
const auto &item = collage.items[index];
if (const auto photo = base::get_if<PhotoData*>(&item)) {
if (const auto photo = std::get_if<PhotoData*>(&item)) {
return createThumb(key, (*photo));
} else if (const auto document = base::get_if<DocumentData*>(&item)) {
} else if (const auto document = std::get_if<DocumentData*>(&item)) {
return createThumb(key, (*document));
}
return createThumb(key, nullptr);

View File

@ -37,7 +37,7 @@ public:
int size() const;
};
using Key = base::variant<PhotoId, FullMsgId, CollageKey>;
using Key = std::variant<PhotoId, FullMsgId, CollageKey>;
static void Refresh(
not_null<Main::Session*> session,

View File

@ -1116,7 +1116,7 @@ void OverlayWidget::clearSession() {
clearStreaming();
delete _menu;
_menu = nullptr;
setContext(std::nullopt);
setContext(v::null);
_from = nullptr;
_fromName = QString();
assignMediaPointer(nullptr);
@ -1589,7 +1589,7 @@ auto OverlayWidget::sharedMediaKey() const -> std::optional<SharedMediaKey> {
_history->peer->id,
_migrated ? _migrated->peer->id : 0,
SharedMediaType::ChatPhoto,
_peer->userpicPhotoId()
_photo
};
}
if (!IsServerMsgId(_msgid.msg)) {
@ -1947,12 +1947,12 @@ void OverlayWidget::initGroupThumbs() {
_groupThumbs->activateRequests(
) | rpl::start_with_next([this](View::GroupThumbs::Key key) {
using CollageKey = View::GroupThumbs::CollageKey;
if (const auto photoId = base::get_if<PhotoId>(&key)) {
if (const auto photoId = std::get_if<PhotoId>(&key)) {
const auto photo = _session->data().photo(*photoId);
moveToEntity({ photo, nullptr });
} else if (const auto itemId = base::get_if<FullMsgId>(&key)) {
} else if (const auto itemId = std::get_if<FullMsgId>(&key)) {
moveToEntity(entityForItemId(*itemId));
} else if (const auto collageKey = base::get_if<CollageKey>(&key)) {
} else if (const auto collageKey = std::get_if<CollageKey>(&key)) {
if (_collageData) {
moveToEntity(entityForCollage(collageKey->index));
}
@ -1990,7 +1990,7 @@ void OverlayWidget::showPhoto(
if (context) {
setContext(context);
} else {
setContext(std::nullopt);
setContext(v::null);
}
clearControlsState();
@ -2039,7 +2039,7 @@ void OverlayWidget::showDocument(
if (context) {
setContext(context);
} else {
setContext(std::nullopt);
setContext(v::null);
}
clearControlsState();
@ -2490,7 +2490,7 @@ QImage OverlayWidget::transformStaticContent(QPixmap content) const {
void OverlayWidget::handleStreamingUpdate(Streaming::Update &&update) {
using namespace Streaming;
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
streamingReady(std::move(update));
}, [&](const PreloadedVideo &update) {
updatePlaybackState();
@ -3535,29 +3535,29 @@ OverlayWidget::Entity OverlayWidget::entityForUserPhotos(int index) const {
Expects(_session != nullptr);
if (index < 0 || index >= _userPhotosData->size()) {
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
const auto id = (*_userPhotosData)[index];
if (const auto photo = _session->data().photo(id)) {
return { photo, nullptr };
}
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
OverlayWidget::Entity OverlayWidget::entityForSharedMedia(int index) const {
Expects(_sharedMediaData.has_value());
if (index < 0 || index >= _sharedMediaData->size()) {
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
auto value = (*_sharedMediaData)[index];
if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
if (const auto photo = std::get_if<not_null<PhotoData*>>(&value)) {
// Last peer photo.
return { *photo, nullptr };
} else if (const auto itemId = base::get_if<FullMsgId>(&value)) {
} else if (const auto itemId = std::get_if<FullMsgId>(&value)) {
return entityForItemId(*itemId);
}
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
OverlayWidget::Entity OverlayWidget::entityForCollage(int index) const {
@ -3567,14 +3567,14 @@ OverlayWidget::Entity OverlayWidget::entityForCollage(int index) const {
const auto item = _session->data().message(_msgid);
const auto &items = _collageData->items;
if (!item || index < 0 || index >= items.size()) {
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
if (const auto document = base::get_if<DocumentData*>(&items[index])) {
if (const auto document = std::get_if<DocumentData*>(&items[index])) {
return { *document, item };
} else if (const auto photo = base::get_if<PhotoData*>(&items[index])) {
} else if (const auto photo = std::get_if<PhotoData*>(&items[index])) {
return { *photo, item };
}
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
OverlayWidget::Entity OverlayWidget::entityForItemId(const FullMsgId &itemId) const {
@ -3588,9 +3588,9 @@ OverlayWidget::Entity OverlayWidget::entityForItemId(const FullMsgId &itemId) co
return { document, item };
}
}
return { std::nullopt, item };
return { v::null, item };
}
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
OverlayWidget::Entity OverlayWidget::entityByIndex(int index) const {
@ -3601,7 +3601,7 @@ OverlayWidget::Entity OverlayWidget::entityByIndex(int index) const {
} else if (_collageData) {
return entityForCollage(index);
}
return { std::nullopt, nullptr };
return { v::null, nullptr };
}
void OverlayWidget::setContext(
@ -3689,7 +3689,7 @@ bool OverlayWidget::moveToEntity(const Entity &entity, int preloadDelta) {
} else if (_peer) {
setContext(_peer);
} else {
setContext(std::nullopt);
setContext(v::null);
}
clearStreaming();
_streamingStartPaused = false;

View File

@ -1326,7 +1326,7 @@ void Pip::paintPlaybackTexts(QPainter &p) const {
void Pip::handleStreamingUpdate(Streaming::Update &&update) {
using namespace Streaming;
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
_panel.setAspectRatio(
FlipSizeByRotation(update.video.size, _rotation));
}, [&](const PreloadedVideo &update) {

View File

@ -162,12 +162,18 @@ class Sender {
return std::move(_done);
}
RPCFailHandlerPtr takeOnFail() {
if (auto handler = base::get_if<FailPlainHandler>(&_fail)) {
return std::make_shared<FailHandler<FailPlainPolicy>>(_sender, std::move(*handler), _failSkipPolicy);
} else if (auto handler = base::get_if<FailRequestIdHandler>(&_fail)) {
return std::make_shared<FailHandler<FailRequestIdPolicy>>(_sender, std::move(*handler), _failSkipPolicy);
}
return RPCFailHandlerPtr();
return v::match(_fail, [&](FailPlainHandler &value)
-> RPCFailHandlerPtr {
return std::make_shared<FailHandler<FailPlainPolicy>>(
_sender,
std::move(value),
_failSkipPolicy);
}, [&](FailRequestIdHandler &value) -> RPCFailHandlerPtr {
return std::make_shared<FailHandler<FailRequestIdPolicy>>(
_sender,
std::move(value),
_failSkipPolicy);
});
}
mtpRequestId takeAfter() const noexcept {
return _afterRequestId;
@ -185,7 +191,7 @@ class Sender {
ShiftedDcId _dcId = 0;
crl::time _canWait = 0;
RPCDoneHandlerPtr _done;
base::variant<FailPlainHandler, FailRequestIdHandler> _fail;
std::variant<FailPlainHandler, FailRequestIdHandler> _fail;
FailSkipPolicy _failSkipPolicy = FailSkipPolicy::Simple;
mtpRequestId _afterRequestId = 0;

View File

@ -64,7 +64,7 @@ struct ScopeError {
// FileKey - file_hash error (bad scan / selfie / translation)
// General - general value error (or scan / translation missing)
// QString - data_hash with such key error (bad value)
base::variant<FileKey, General, QString> key;
std::variant<FileKey, General, QString> key;
QString text;
};

View File

@ -37,7 +37,7 @@ constexpr auto kJpegQuality = 89;
static_assert(kMaxSize <= Storage::kUseBigFilesFrom);
base::variant<ReadScanError, QByteArray> ProcessImage(QByteArray &&bytes) {
std::variant<ReadScanError, QByteArray> ProcessImage(QByteArray &&bytes) {
auto image = App::readImage(base::take(bytes));
if (image.isNull()) {
return ReadScanError::CantReadImage;
@ -901,10 +901,10 @@ void EditScans::ChooseScan(
remainingFiles = std::move(remainingFiles)
]() mutable {
auto result = ProcessImage(std::move(bytes));
if (const auto error = base::get_if<ReadScanError>(&result)) {
if (const auto error = std::get_if<ReadScanError>(&result)) {
onMainError(*error);
} else {
auto content = base::get_if<QByteArray>(&result);
auto content = std::get_if<QByteArray>(&result);
Assert(content != nullptr);
crl::on_main([
=,

View File

@ -216,7 +216,11 @@ private:
};
struct ClearFinish {
};
using ClearTask = base::variant<ClearFromHistory, ClearFromSession, ClearAll, ClearFinish>;
using ClearTask = std::variant<
ClearFromHistory,
ClearFromSession,
ClearAll,
ClearFinish>;
std::vector<ClearTask> _clearingTasks;
};
@ -285,21 +289,20 @@ void Manager::Private::clearingThreadLoop() {
auto clearFromSessions = base::flat_set<uint64>();
{
std::unique_lock<std::mutex> lock(_clearingMutex);
while (_clearingTasks.empty()) {
_clearingCondition.wait(lock);
}
for (auto &task : _clearingTasks) {
if (base::get_if<ClearFinish>(&task)) {
v::match(task, [&](ClearFinish) {
finished = true;
clearAll = true;
} else if (base::get_if<ClearAll>(&task)) {
}, [&](ClearAll) {
clearAll = true;
} else if (auto fromHistory = base::get_if<ClearFromHistory>(&task)) {
clearFromPeers.emplace(fromHistory->fullPeer);
} else if (auto fromSession = base::get_if<ClearFromSession>(&task)) {
clearFromSessions.emplace(fromSession->sessionId);
}
}, [&](const ClearFromHistory &value) {
clearFromPeers.emplace(value.fullPeer);
}, [&](const ClearFromSession &value) {
clearFromSessions.emplace(value.sessionId);
});
}
_clearingTasks.clear();
}

View File

@ -442,7 +442,7 @@ Data::FileOrigin DownloadMtprotoTask::fileOrigin() const {
}
uint64 DownloadMtprotoTask::objectId() const {
if (const auto v = base::get_if<StorageFileLocation>(&_location.data)) {
if (const auto v = std::get_if<StorageFileLocation>(&_location.data)) {
return v->objectId();
}
return 0;
@ -456,7 +456,7 @@ void DownloadMtprotoTask::refreshFileReferenceFrom(
const Data::UpdatedFileReferences &updates,
int requestId,
const QByteArray &current) {
if (const auto v = base::get_if<StorageFileLocation>(&_location.data)) {
if (const auto v = std::get_if<StorageFileLocation>(&_location.data)) {
v->refreshFileReference(updates);
if (v->fileReference() == current) {
cancelOnFail();
@ -525,7 +525,7 @@ mtpRequestId DownloadMtprotoTask::sendRequest(
cdnPartFailed(error, id);
}).toDC(shiftedDcId).send();
}
return _location.data.match([&](const WebFileLocation &location) {
return v::match(_location.data, [&](const WebFileLocation &location) {
return api().request(MTPupload_GetWebFile(
MTP_inputWebFileLocation(
MTP_bytes(location.url()),

View File

@ -120,7 +120,7 @@ private:
class DownloadMtprotoTask : public base::has_weak_ptr {
public:
struct Location {
base::variant<
std::variant<
StorageFileLocation,
WebFileLocation,
GeoPointLocation> data;

View File

@ -488,7 +488,7 @@ std::unique_ptr<FileLoader> CreateFileLoader(
bool autoLoading,
uint8 cacheTag) {
auto result = std::unique_ptr<FileLoader>();
location.data.match([&](const StorageFileLocation &data) {
v::match(location.data, [&](const StorageFileLocation &data) {
result = std::make_unique<mtpFileLoader>(
session,
data,

View File

@ -179,7 +179,7 @@ void mtpFileLoader::cancelHook() {
}
Storage::Cache::Key mtpFileLoader::cacheKey() const {
return location().data.match([&](const WebFileLocation &location) {
return v::match(location().data, [&](const WebFileLocation &location) {
return Data::WebDocumentCacheKey(location);
}, [&](const GeoPointLocation &location) {
return Data::GeoPointCacheKey(location);

View File

@ -44,7 +44,7 @@ struct Progress {
qint64 total = 0;
};
using Update = base::variant<Progress, QByteArray, Error>;
using Update = std::variant<Progress, QByteArray, Error>;
struct UpdateForLoader {
not_null<webFileLoader*> loader;
@ -473,9 +473,9 @@ void webFileLoader::startLoading() {
_manager->updates(
this
) | rpl::start_with_next([=](const Update &data) {
if (const auto progress = base::get_if<Progress>(&data)) {
if (const auto progress = std::get_if<Progress>(&data)) {
loadProgress(progress->ready, progress->total);
} else if (const auto bytes = base::get_if<QByteArray>(&data)) {
} else if (const auto bytes = std::get_if<QByteArray>(&data)) {
loadFinished(*bytes);
} else {
loadFailed();

View File

@ -144,7 +144,7 @@ DocumentData *Document::readFromStreamHelper(
}
}
const auto storage = base::get_if<StorageFileLocation>(
const auto storage = std::get_if<StorageFileLocation>(
&thumb->file().data);
if ((stream.status() != QDataStream::Ok)
|| (!dc && !access)

View File

@ -69,7 +69,7 @@ bool UnpackBlob(
}
QString StateDescription(const BlobState &state, tr::phrase<> activeText) {
return state.match([](const Available &data) {
return v::match(state, [](const Available &data) {
return tr::lng_emoji_set_download(
tr::now,
lt_size,

View File

@ -65,7 +65,7 @@ struct Failed {
};
using Loading = MTP::DedicatedLoader::Progress;
using BlobState = base::variant<
using BlobState = std::variant<
Available,
Ready,
Active,

View File

@ -621,7 +621,7 @@ InMemoryKey inMemoryKey(const InMemoryLocation &location) {
}
InMemoryKey inMemoryKey(const DownloadLocation &location) {
return location.data.match([](const auto &data) {
return v::match(location.data, [](const auto &data) {
return inMemoryKey(data);
});
}
@ -681,8 +681,8 @@ std::optional<StorageImageLocation> StorageImageLocation::FromSerialized(
}
QByteArray DownloadLocation::serialize() const {
if (!valid() || data.is<StorageFileLocation>()) {
return data.get_unchecked<StorageFileLocation>().serialize();
if (!valid() || v::is<StorageFileLocation>(data)) {
return std::get<StorageFileLocation>(data).serialize();
}
auto result = QByteArray();
auto buffer = QBuffer(&result);
@ -691,7 +691,7 @@ QByteArray DownloadLocation::serialize() const {
stream.setVersion(QDataStream::Qt_5_1);
stream << quint16(0) << kNonStorageLocationToken;
data.match([&](const StorageFileLocation &data) {
v::match(data, [&](const StorageFileLocation &data) {
Unexpected("Variant in DownloadLocation::serialize.");
}, [&](const WebFileLocation &data) {
stream
@ -718,11 +718,11 @@ QByteArray DownloadLocation::serialize() const {
}
int DownloadLocation::serializeSize() const {
if (!valid() || data.is<StorageFileLocation>()) {
return data.get_unchecked<StorageFileLocation>().serializeSize();
if (!valid() || v::is<StorageFileLocation>(data)) {
return std::get<StorageFileLocation>(data).serializeSize();
}
auto result = sizeof(quint16) + sizeof(quint8) + sizeof(quint8);
data.match([&](const StorageFileLocation &data) {
v::match(data, [&](const StorageFileLocation &data) {
Unexpected("Variant in DownloadLocation::serializeSize.");
}, [&](const WebFileLocation &data) {
result += Serialize::bytearraySize(data.url()) + sizeof(quint64);
@ -809,15 +809,15 @@ DownloadLocation DownloadLocation::convertToModern(
StorageFileLocation::Type type,
uint64 id,
uint64 accessHash) const {
if (!data.is<StorageFileLocation>()) {
if (!v::is<StorageFileLocation>(data)) {
return *this;
}
auto &file = data.get_unchecked<StorageFileLocation>();
auto &file = std::get<StorageFileLocation>(data);
return DownloadLocation{ file.convertToModern(type, id, accessHash) };
}
Storage::Cache::Key DownloadLocation::cacheKey() const {
return data.match([](const GeoPointLocation &data) {
return v::match(data, [](const GeoPointLocation &data) {
return Data::GeoPointCacheKey(data);
}, [](const StorageFileLocation &data) {
return data.valid()
@ -837,13 +837,13 @@ Storage::Cache::Key DownloadLocation::cacheKey() const {
}
Storage::Cache::Key DownloadLocation::bigFileBaseCacheKey() const {
return data.is<StorageFileLocation>()
? data.get_unchecked<StorageFileLocation>().bigFileBaseCacheKey()
return v::is<StorageFileLocation>(data)
? std::get<StorageFileLocation>(data).bigFileBaseCacheKey()
: Storage::Cache::Key();
}
bool DownloadLocation::valid() const {
return data.match([](const GeoPointLocation &data) {
return v::match(data, [](const GeoPointLocation &data) {
return true;
}, [](const StorageFileLocation &data) {
return data.valid();
@ -857,32 +857,32 @@ bool DownloadLocation::valid() const {
}
bool DownloadLocation::isLegacy() const {
return data.is<StorageFileLocation>()
? data.get_unchecked<StorageFileLocation>().isLegacy()
return v::is<StorageFileLocation>(data)
? std::get<StorageFileLocation>(data).isLegacy()
: false;
}
QByteArray DownloadLocation::fileReference() const {
if (!data.is<StorageFileLocation>()) {
if (!v::is<StorageFileLocation>(data)) {
return QByteArray();
}
return data.get_unchecked<StorageFileLocation>().fileReference();
return std::get<StorageFileLocation>(data).fileReference();
}
bool DownloadLocation::refreshFileReference(const QByteArray &data) {
if (!this->data.is<StorageFileLocation>()) {
if (!v::is<StorageFileLocation>(this->data)) {
return false;
}
auto &file = this->data.get_unchecked<StorageFileLocation>();
auto &file = std::get<StorageFileLocation>(this->data);
return file.refreshFileReference(data);
}
bool DownloadLocation::refreshFileReference(
const Data::UpdatedFileReferences &updates) {
if (!data.is<StorageFileLocation>()) {
if (!v::is<StorageFileLocation>(data)) {
return false;
}
auto &file = data.get_unchecked<StorageFileLocation>();
auto &file = std::get<StorageFileLocation>(data);
return file.refreshFileReference(updates);
}

View File

@ -446,7 +446,7 @@ inline bool operator>=(
class DownloadLocation {
public:
base::variant<
std::variant<
StorageFileLocation,
WebFileLocation,
GeoPointLocation,

View File

@ -865,7 +865,7 @@ void UserpicButton::clearStreaming() {
void UserpicButton::handleStreamingUpdate(Media::Streaming::Update &&update) {
using namespace Media::Streaming;
update.data.match([&](Information &update) {
v::match(update.data, [&](Information &update) {
streamingReady(std::move(update));
}, [&](const PreloadedVideo &update) {
}, [&](const UpdateVideo &update) {

View File

@ -248,7 +248,7 @@ void MediaPreviewWidget::setupLottie() {
_lottie->updates(
) | rpl::start_with_next([=](Lottie::Update update) {
update.data.match([&](const Lottie::Information &) {
v::match(update.data, [&](const Lottie::Information &) {
this->update();
}, [&](const Lottie::DisplayFrameRequest &) {
this->update(updateArea());

@ -1 +1 @@
Subproject commit e94515700a622c2424f58d32e670581e9185f7e7
Subproject commit 0060349806529cd517201bec2d25208ad8d0bb89

@ -1 +1 @@
Subproject commit b666e438be285b2781d93ac64138ab32ab4a85e0
Subproject commit b060b25b45bf0100ae6d35f558eb0818380ebc13

@ -1 +1 @@
Subproject commit b58d2804acda906119c53c1fa1a2593fa9895878
Subproject commit e654c5ee98199b47a426aaaf6a1f7331aca0ebcd

@ -1 +1 @@
Subproject commit 538a72e5d3aedb660d3a399cc883067ada16e9cf
Subproject commit 52b8d0456fec25f80ca96e6d354dd7583f7fa350