Move to std::optional.

This commit is contained in:
John Preston 2018-09-21 19:28:46 +03:00
parent 850efbde95
commit 2e5a0e056c
115 changed files with 632 additions and 672 deletions

View file

@ -1927,7 +1927,7 @@ void ApiWrap::handlePrivacyChange(
mtpTypeId keyTypeId, mtpTypeId keyTypeId,
const MTPVector<MTPPrivacyRule> &rules) { const MTPVector<MTPPrivacyRule> &rules) {
using Key = Privacy::Key; using Key = Privacy::Key;
const auto key = [&]() -> base::optional<Key> { const auto key = [&]() -> std::optional<Key> {
switch (keyTypeId) { switch (keyTypeId) {
case mtpc_privacyKeyStatusTimestamp: case mtpc_privacyKeyStatusTimestamp:
case mtpc_inputPrivacyKeyStatusTimestamp: return Key::LastSeen; case mtpc_inputPrivacyKeyStatusTimestamp: return Key::LastSeen;
@ -1936,7 +1936,7 @@ void ApiWrap::handlePrivacyChange(
case mtpc_privacyKeyPhoneCall: case mtpc_privacyKeyPhoneCall:
case mtpc_inputPrivacyKeyPhoneCall: return Key::Calls; case mtpc_inputPrivacyKeyPhoneCall: return Key::Calls;
} }
return base::none; return std::nullopt;
}(); }();
if (!key) { if (!key) {
return; return;
@ -2582,7 +2582,7 @@ void ApiWrap::refreshFileReference(
request( request(
MTPmessages_GetSavedGifs(MTP_int(0)), MTPmessages_GetSavedGifs(MTP_int(0)),
[] { crl::on_main([] { Local::writeSavedGifs(); }); }); [] { crl::on_main([] { Local::writeSavedGifs(); }); });
}, [&](base::none_type) { }, [&](std::nullopt_t) {
fail(); fail();
}); });
} }
@ -4236,7 +4236,7 @@ void ApiWrap::sendUploadedPhoto(
void ApiWrap::sendUploadedDocument( void ApiWrap::sendUploadedDocument(
FullMsgId localId, FullMsgId localId,
const MTPInputFile &file, const MTPInputFile &file,
const base::optional<MTPInputFile> &thumb, const std::optional<MTPInputFile> &thumb,
bool silent) { bool silent) {
if (const auto item = App::histItemById(localId)) { if (const auto item = App::histItemById(localId)) {
auto media = item->media(); auto media = item->media();
@ -4987,10 +4987,10 @@ rpl::producer<Core::CloudPasswordState> ApiWrap::passwordState() const {
} }
auto ApiWrap::passwordStateCurrent() const auto ApiWrap::passwordStateCurrent() const
->base::optional<Core::CloudPasswordState> { ->std::optional<Core::CloudPasswordState> {
return _passwordState return _passwordState
? base::make_optional(*_passwordState) ? base::make_optional(*_passwordState)
: base::none; : std::nullopt;
} }
void ApiWrap::saveSelfBio(const QString &text, FnMut<void()> done) { void ApiWrap::saveSelfBio(const QString &text, FnMut<void()> done) {

View file

@ -304,7 +304,7 @@ public:
void sendUploadedDocument( void sendUploadedDocument(
FullMsgId localId, FullMsgId localId,
const MTPInputFile &file, const MTPInputFile &file,
const base::optional<MTPInputFile> &thumb, const std::optional<MTPInputFile> &thumb,
bool silent); bool silent);
void cancelLocalItem(not_null<HistoryItem*> item); void cancelLocalItem(not_null<HistoryItem*> item);
@ -336,7 +336,7 @@ public:
void reloadPasswordState(); void reloadPasswordState();
void clearUnconfirmedPassword(); void clearUnconfirmedPassword();
rpl::producer<Core::CloudPasswordState> passwordState() const; rpl::producer<Core::CloudPasswordState> passwordState() const;
base::optional<Core::CloudPasswordState> passwordStateCurrent() const; std::optional<Core::CloudPasswordState> passwordStateCurrent() const;
void saveSelfBio(const QString &text, FnMut<void()> done); void saveSelfBio(const QString &text, FnMut<void()> done);
@ -717,7 +717,7 @@ private:
std::map<Privacy::Key, rpl::event_stream<Privacy>> _privacyChanges; std::map<Privacy::Key, rpl::event_stream<Privacy>> _privacyChanges;
mtpRequestId _selfDestructRequestId = 0; mtpRequestId _selfDestructRequestId = 0;
base::optional<int> _selfDestructDays; std::optional<int> _selfDestructDays;
rpl::event_stream<int> _selfDestructChanges; rpl::event_stream<int> _selfDestructChanges;
}; };

View file

@ -722,10 +722,10 @@ public:
return where->second; return where->second;
} }
optional<Type> take(const Key &key) { std::optional<Type> take(const Key &key) {
auto it = find(key); auto it = find(key);
if (it == this->end()) { if (it == this->end()) {
return base::none; return std::nullopt;
} }
auto result = std::move(it->second); auto result = std::move(it->second);
this->erase(it); this->erase(it);

View file

@ -7,39 +7,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include <optional>
#include <gsl/gsl_assert> #include <gsl/gsl_assert>
#include "base/variant.h" #include "base/variant.h"
namespace base { namespace base {
struct none_type {
bool operator==(none_type other) const {
return true;
}
bool operator!=(none_type other) const {
return false;
}
bool operator<(none_type other) const {
return false;
}
bool operator<=(none_type other) const {
return true;
}
bool operator>(none_type other) const {
return false;
}
bool operator>=(none_type other) const {
return true;
}
};
constexpr none_type none = {};
template <typename... Types> template <typename... Types>
class optional_variant { class optional_variant {
public: public:
optional_variant() : _impl(none) { optional_variant() : _impl(std::nullopt) {
} }
optional_variant(const optional_variant &other) : _impl(other._impl) { optional_variant(const optional_variant &other) : _impl(other._impl) {
} }
@ -63,7 +40,7 @@ public:
} }
bool has_value() const { bool has_value() const {
return !is<none_type>(); return !is<std::nullopt_t>();
} }
explicit operator bool() const { explicit operator bool() const {
return has_value(); return has_value();
@ -93,7 +70,7 @@ public:
return get_unchecked<T>(); return get_unchecked<T>();
} }
void clear() { void clear() {
_impl.template set<none_type>(); _impl.template set<std::nullopt_t>();
} }
template <typename T> template <typename T>
@ -119,7 +96,7 @@ public:
} }
private: private:
variant<none_type, Types...> _impl; variant<std::nullopt_t, Types...> _impl;
}; };
@ -147,17 +124,14 @@ inline decltype(auto) match(
return value.match(std::forward<Methods>(methods)...); return value.match(std::forward<Methods>(methods)...);
} }
template <typename Type>
class optional;
template <typename Type> template <typename Type>
struct optional_wrap_once { struct optional_wrap_once {
using type = optional<Type>; using type = std::optional<Type>;
}; };
template <typename Type> template <typename Type>
struct optional_wrap_once<optional<Type>> { struct optional_wrap_once<std::optional<Type>> {
using type = optional<Type>; using type = std::optional<Type>;
}; };
template <typename Type> template <typename Type>
@ -176,58 +150,22 @@ struct optional_chain_result<void> {
template <typename Type> template <typename Type>
using optional_chain_result_t = typename optional_chain_result<Type>::type; using optional_chain_result_t = typename optional_chain_result<Type>::type;
template <typename Type>
class optional : public optional_variant<Type> {
using parent = optional_variant<Type>;
public:
using parent::parent;
Type &operator*() & {
Expects(parent::template is<Type>());
return parent::template get_unchecked<Type>();
}
Type &&operator*() && {
Expects(parent::template is<Type>());
return std::move(parent::template get_unchecked<Type>());
}
const Type &operator*() const & {
Expects(parent::template is<Type>());
return parent::template get_unchecked<Type>();
}
Type *operator->() {
Expects(parent::template is<Type>());
return std::addressof(parent::template get_unchecked<Type>());
}
const Type *operator->() const {
Expects(parent::template is<Type>());
return std::addressof(parent::template get_unchecked<Type>());
}
template <typename ...Args>
Type &emplace(Args &&...args) {
return parent::template set<Type>(std::forward<Args>(args)...);
}
};
template <typename Type> template <typename Type>
optional_wrap_once_t<Type> make_optional(Type &&value) { optional_wrap_once_t<Type> make_optional(Type &&value) {
return optional_wrap_once_t<Type> { std::forward<Type>(value) }; return optional_wrap_once_t<Type> { std::forward<Type>(value) };
} }
} // namespace base
template <typename Type, typename Method> template <typename Type, typename Method>
inline auto operator|(const optional<Type> &value, Method method) inline auto operator|(const std::optional<Type> &value, Method method)
-> optional_chain_result_t<decltype(method(*value))> { -> base::optional_chain_result_t<decltype(method(*value))> {
if constexpr (std::is_same_v<decltype(method(*value)), void>) { if constexpr (std::is_same_v<decltype(method(*value)), void>) {
return value ? (method(*value), true) : false; return value ? (method(*value), true) : false;
} else { } else {
return value ? make_optional(method(*value)) : none; return value
? base::optional_chain_result_t<decltype(method(*value))>(
method(*value))
: std::nullopt;
} }
} }
} // namespace base

View file

@ -7,6 +7,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include <optional>
inline bool operator<(std::nullopt_t, std::nullopt_t) {
return false;
}
inline bool operator>(std::nullopt_t, std::nullopt_t) {
return false;
}
inline bool operator<=(std::nullopt_t, std::nullopt_t) {
return true;
}
inline bool operator>=(std::nullopt_t, std::nullopt_t) {
return true;
}
inline bool operator==(std::nullopt_t, std::nullopt_t) {
return true;
}
inline bool operator!=(std::nullopt_t, std::nullopt_t) {
return false;
}
#include <mapbox/variant.hpp> #include <mapbox/variant.hpp>
#include <rpl/details/type_list.h> #include <rpl/details/type_list.h>
#include "base/match_method.h" #include "base/match_method.h"

View file

@ -414,7 +414,7 @@ void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QStr
App::main()->sentUpdatesReceived(result); App::main()->sentUpdatesReceived(result);
auto success = base::make_optional(&result) auto success = base::make_optional(&result)
| [](auto updates) -> base::optional<const QVector<MTPChat>*> { | [](auto updates) -> std::optional<const QVector<MTPChat>*> {
switch (updates->type()) { switch (updates->type()) {
case mtpc_updates: case mtpc_updates:
return &updates->c_updates().vchats.v; return &updates->c_updates().vchats.v;
@ -422,12 +422,12 @@ void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QStr
return &updates->c_updatesCombined().vchats.v; return &updates->c_updatesCombined().vchats.v;
} }
LOG(("API Error: unexpected update cons %1 (GroupInfoBox::creationDone)").arg(updates->type())); LOG(("API Error: unexpected update cons %1 (GroupInfoBox::creationDone)").arg(updates->type()));
return base::none; return std::nullopt;
} }
| [](auto chats) { | [](auto chats) {
return (!chats->empty() && chats->front().type() == mtpc_chat) return (!chats->empty() && chats->front().type() == mtpc_chat)
? base::make_optional(chats) ? base::make_optional(chats)
: base::none; : std::nullopt;
} }
| [](auto chats) { | [](auto chats) {
return App::chat(chats->front().c_chat().vid.v); return App::chat(chats->front().c_chat().vid.v);
@ -517,7 +517,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
App::main()->sentUpdatesReceived(result); App::main()->sentUpdatesReceived(result);
auto success = base::make_optional(&result) auto success = base::make_optional(&result)
| [](auto updates) -> base::optional<const QVector<MTPChat>*> { | [](auto updates) -> std::optional<const QVector<MTPChat>*> {
switch (updates->type()) { switch (updates->type()) {
case mtpc_updates: case mtpc_updates:
return &updates->c_updates().vchats.v; return &updates->c_updates().vchats.v;
@ -525,12 +525,12 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
return &updates->c_updatesCombined().vchats.v; return &updates->c_updatesCombined().vchats.v;
} }
LOG(("API Error: unexpected update cons %1 (GroupInfoBox::createChannel)").arg(updates->type())); LOG(("API Error: unexpected update cons %1 (GroupInfoBox::createChannel)").arg(updates->type()));
return base::none; return std::nullopt;
} }
| [](auto chats) { | [](auto chats) {
return (!chats->empty() && chats->front().type() == mtpc_channel) return (!chats->empty() && chats->front().type() == mtpc_channel)
? base::make_optional(chats) ? base::make_optional(chats)
: base::none; : std::nullopt;
} }
| [](auto chats) { | [](auto chats) {
return App::channel(chats->front().c_channel().vid.v); return App::channel(chats->front().c_channel().vid.v);

View file

@ -93,12 +93,12 @@ private:
Ui::Checkbox *signatures = nullptr; Ui::Checkbox *signatures = nullptr;
}; };
struct Saving { struct Saving {
base::optional<QString> username; std::optional<QString> username;
base::optional<QString> title; std::optional<QString> title;
base::optional<QString> description; std::optional<QString> description;
base::optional<bool> hiddenPreHistory; std::optional<bool> hiddenPreHistory;
base::optional<bool> signatures; std::optional<bool> signatures;
base::optional<bool> everyoneInvites; std::optional<bool> everyoneInvites;
}; };
Fn<QString()> computeTitle() const; Fn<QString()> computeTitle() const;
@ -143,7 +143,7 @@ private:
void revokeInviteLink(); void revokeInviteLink();
void exportInviteLink(const QString &confirmation); void exportInviteLink(const QString &confirmation);
base::optional<Saving> validate() const; std::optional<Saving> validate() const;
bool validateUsername(Saving &to) const; bool validateUsername(Saving &to) const;
bool validateTitle(Saving &to) const; bool validateTitle(Saving &to) const;
bool validateDescription(Saving &to) const; bool validateDescription(Saving &to) const;
@ -1087,7 +1087,7 @@ void Controller::submitDescription() {
} }
} }
base::optional<Controller::Saving> Controller::validate() const { std::optional<Controller::Saving> Controller::validate() const {
auto result = Saving(); auto result = Saving();
if (validateUsername(result) if (validateUsername(result)
&& validateTitle(result) && validateTitle(result)

View file

@ -44,7 +44,7 @@ private:
bool reportFail(const RPCError &error); bool reportFail(const RPCError &error);
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
base::optional<MessageIdsList> _ids; std::optional<MessageIdsList> _ids;
std::shared_ptr<Ui::RadioenumGroup<Reason>> _reasonGroup; std::shared_ptr<Ui::RadioenumGroup<Reason>> _reasonGroup;
object_ptr<Ui::Radioenum<Reason>> _reasonSpam = { nullptr }; object_ptr<Ui::Radioenum<Reason>> _reasonSpam = { nullptr };

View file

@ -136,7 +136,7 @@ private:
void drawSimpleFrame(Painter &p, QRect to, QSize size) const; void drawSimpleFrame(Painter &p, QRect to, QSize size) const;
Ui::GroupMediaLayout _layout; Ui::GroupMediaLayout _layout;
base::optional<QRect> _animateFromGeometry; std::optional<QRect> _animateFromGeometry;
const QImage _fullPreview; const QImage _fullPreview;
const int _shrinkSize = 0; const int _shrinkSize = 0;
QPixmap _albumImage; QPixmap _albumImage;
@ -229,7 +229,7 @@ AlbumThumb::AlbumThumb(
} }
void AlbumThumb::resetLayoutAnimation() { void AlbumThumb::resetLayoutAnimation() {
_animateFromGeometry = base::none; _animateFromGeometry = std::nullopt;
} }
void AlbumThumb::animateLayoutToInitial() { void AlbumThumb::animateLayoutToInitial() {

View file

@ -239,7 +239,7 @@ void MoveFavedToFront(Set &set, int index) {
void RequestSetToPushFaved(not_null<DocumentData*> document); void RequestSetToPushFaved(not_null<DocumentData*> document);
void SetIsFaved(not_null<DocumentData*> document, base::optional<std::vector<not_null<EmojiPtr>>> emojiList = base::none) { void SetIsFaved(not_null<DocumentData*> document, std::optional<std::vector<not_null<EmojiPtr>>> emojiList = std::nullopt) {
auto &sets = Auth().data().stickerSetsRef(); auto &sets = Auth().data().stickerSetsRef();
auto it = sets.find(FavedSetId); auto it = sets.find(FavedSetId);
if (it == sets.end()) { if (it == sets.end()) {
@ -825,17 +825,17 @@ std::vector<not_null<DocumentData*>> GetListByEmoji(
}) | ranges::to_vector; }) | ranges::to_vector;
} }
base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet( std::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
not_null<DocumentData*> document) { not_null<DocumentData*> document) {
if (auto sticker = document->sticker()) { if (auto sticker = document->sticker()) {
auto &inputSet = sticker->set; auto &inputSet = sticker->set;
if (inputSet.type() != mtpc_inputStickerSetID) { if (inputSet.type() != mtpc_inputStickerSetID) {
return base::none; return std::nullopt;
} }
auto &sets = Auth().data().stickerSets(); auto &sets = Auth().data().stickerSets();
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v); auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v);
if (it == sets.cend()) { if (it == sets.cend()) {
return base::none; return std::nullopt;
} }
auto result = std::vector<not_null<EmojiPtr>>(); auto result = std::vector<not_null<EmojiPtr>>();
for (auto i = it->emoji.cbegin(), e = it->emoji.cend(); i != e; ++i) { for (auto i = it->emoji.cbegin(), e = it->emoji.cend(); i != e; ++i) {
@ -844,11 +844,11 @@ base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
} }
} }
if (result.empty()) { if (result.empty()) {
return base::none; return std::nullopt;
} }
return std::move(result); return std::move(result);
} }
return base::none; return std::nullopt;
} }
Set *FeedSet(const MTPDstickerSet &set) { Set *FeedSet(const MTPDstickerSet &set) {

View file

@ -89,7 +89,7 @@ void GifsReceived(const QVector<MTPDocument> &items, int32 hash);
std::vector<not_null<DocumentData*>> GetListByEmoji( std::vector<not_null<DocumentData*>> GetListByEmoji(
not_null<EmojiPtr> emoji, not_null<EmojiPtr> emoji,
uint64 seed); uint64 seed);
base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet( std::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
not_null<DocumentData*> document); not_null<DocumentData*> document);
Set *FeedSet(const MTPDstickerSet &data); Set *FeedSet(const MTPDstickerSet &data);

View file

@ -1498,7 +1498,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
_previewTimer.stop(); _previewTimer.stop();
auto pressed = _pressed; auto pressed = _pressed;
setPressed(base::none); setPressed(std::nullopt);
if (pressed != _selected) { if (pressed != _selected) {
update(); update();
} }
@ -1652,8 +1652,8 @@ void StickersListWidget::enterFromChildEvent(QEvent *e, QWidget *child) {
} }
void StickersListWidget::clearSelection() { void StickersListWidget::clearSelection() {
setPressed(base::none); setPressed(std::nullopt);
setSelected(base::none); setSelected(std::nullopt);
update(); update();
} }
@ -2058,7 +2058,7 @@ void StickersListWidget::updateSelected() {
return; return;
} }
auto newSelected = OverState { base::none }; auto newSelected = OverState { std::nullopt };
auto p = mapFromGlobal(_lastMousePosition); auto p = mapFromGlobal(_lastMousePosition);
if (!rect().contains(p) if (!rect().contains(p)
|| p.y() < getVisibleTop() || p.y() >= getVisibleBottom() || p.y() < getVisibleTop() || p.y() >= getVisibleBottom()

View file

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

View file

@ -41,10 +41,10 @@ private:
void processArguments(); void processArguments();
QStringList readArguments(int argc, char *argv[]) const; QStringList readArguments(int argc, char *argv[]) const;
virtual base::optional<QStringList> readArgumentsHook( virtual std::optional<QStringList> readArgumentsHook(
int argc, int argc,
char *argv[]) const { char *argv[]) const {
return base::none; return std::nullopt;
} }
void init(); void init();

View file

@ -158,9 +158,9 @@ private:
void gotFailure(QNetworkReply::NetworkError e); void gotFailure(QNetworkReply::NetworkError e);
void clearSentRequest(); void clearSentRequest();
bool handleResponse(const QByteArray &response); bool handleResponse(const QByteArray &response);
base::optional<QString> parseOldResponse( std::optional<QString> parseOldResponse(
const QByteArray &response) const; const QByteArray &response) const;
base::optional<QString> parseResponse(const QByteArray &response) const; std::optional<QString> parseResponse(const QByteArray &response) const;
QString validateLatestUrl( QString validateLatestUrl(
uint64 availableVersion, uint64 availableVersion,
bool isAvailableBeta, bool isAvailableBeta,
@ -262,14 +262,14 @@ private:
const QString &username, const QString &username,
Fn<void(const MTPInputChannel &channel)> callback); Fn<void(const MTPInputChannel &channel)> callback);
void gotMessage(const MTPmessages_Messages &result); void gotMessage(const MTPmessages_Messages &result);
base::optional<FileLocation> parseMessage( std::optional<FileLocation> parseMessage(
const MTPmessages_Messages &result) const; const MTPmessages_Messages &result) const;
base::optional<FileLocation> parseText(const QByteArray &text) const; std::optional<FileLocation> parseText(const QByteArray &text) const;
FileLocation validateLatestLocation( FileLocation validateLatestLocation(
uint64 availableVersion, uint64 availableVersion,
const FileLocation &location) const; const FileLocation &location) const;
void gotFile(const MTPmessages_Messages &result); void gotFile(const MTPmessages_Messages &result);
base::optional<ParsedFile> parseFile( std::optional<ParsedFile> parseFile(
const MTPmessages_Messages &result) const; const MTPmessages_Messages &result) const;
MtpWeak _mtp; MtpWeak _mtp;
@ -597,7 +597,7 @@ bool UnpackUpdate(const QString &filepath) {
return true; return true;
} }
base::optional<MTPInputChannel> ExtractChannel( std::optional<MTPInputChannel> ExtractChannel(
const MTPcontacts_ResolvedPeer &result) { const MTPcontacts_ResolvedPeer &result) {
const auto &data = result.c_contacts_resolvedPeer(); const auto &data = result.c_contacts_resolvedPeer();
if (const auto peer = peerFromMTP(data.vpeer)) { if (const auto peer = peerFromMTP(data.vpeer)) {
@ -612,7 +612,7 @@ base::optional<MTPInputChannel> ExtractChannel(
} }
} }
} }
return base::none; return std::nullopt;
} }
template <typename Callback> template <typename Callback>
@ -717,11 +717,11 @@ bool ParseCommonMap(
return true; return true;
} }
base::optional<MTPMessage> GetMessagesElement( std::optional<MTPMessage> GetMessagesElement(
const MTPmessages_Messages &list) { const MTPmessages_Messages &list) {
const auto get = [](auto &&data) -> base::optional<MTPMessage> { const auto get = [](auto &&data) -> std::optional<MTPMessage> {
return data.vmessages.v.isEmpty() return data.vmessages.v.isEmpty()
? base::none ? std::nullopt
: base::make_optional(data.vmessages.v[0]); : base::make_optional(data.vmessages.v[0]);
}; };
switch (list.type()) { switch (list.type()) {
@ -732,7 +732,7 @@ base::optional<MTPMessage> GetMessagesElement(
case mtpc_messages_channelMessages: case mtpc_messages_channelMessages:
return get(list.c_messages_channelMessages()); return get(list.c_messages_channelMessages());
case mtpc_messages_messagesNotModified: case mtpc_messages_messagesNotModified:
return base::none; return std::nullopt;
default: Unexpected("Type of messages.Messages (GetMessagesElement)"); default: Unexpected("Type of messages.Messages (GetMessagesElement)");
} }
} }
@ -961,14 +961,14 @@ void HttpChecker::gotFailure(QNetworkReply::NetworkError e) {
fail(); fail();
} }
base::optional<QString> HttpChecker::parseOldResponse( std::optional<QString> HttpChecker::parseOldResponse(
const QByteArray &response) const { const QByteArray &response) const {
const auto string = QString::fromLatin1(response); const auto string = QString::fromLatin1(response);
const auto old = QRegularExpression( const auto old = QRegularExpression(
qsl("^\\s*(\\d+)\\s*:\\s*([\\x21-\\x7f]+)\\s*$") qsl("^\\s*(\\d+)\\s*:\\s*([\\x21-\\x7f]+)\\s*$")
).match(string); ).match(string);
if (!old.hasMatch()) { if (!old.hasMatch()) {
return base::none; return std::nullopt;
} }
const auto availableVersion = old.captured(1).toULongLong(); const auto availableVersion = old.captured(1).toULongLong();
const auto url = old.captured(2); const auto url = old.captured(2);
@ -979,7 +979,7 @@ base::optional<QString> HttpChecker::parseOldResponse(
isAvailableBeta ? url.mid(5) + "_{signature}" : url); isAvailableBeta ? url.mid(5) + "_{signature}" : url);
} }
base::optional<QString> HttpChecker::parseResponse( std::optional<QString> HttpChecker::parseResponse(
const QByteArray &response) const { const QByteArray &response) const {
auto bestAvailableVersion = 0ULL; auto bestAvailableVersion = 0ULL;
auto bestIsAvailableBeta = false; auto bestIsAvailableBeta = false;
@ -1005,7 +1005,7 @@ base::optional<QString> HttpChecker::parseResponse(
}; };
const auto result = ParseCommonMap(response, testing(), accumulate); const auto result = ParseCommonMap(response, testing(), accumulate);
if (!result) { if (!result) {
return base::none; return std::nullopt;
} }
return validateLatestUrl( return validateLatestUrl(
bestAvailableVersion, bestAvailableVersion,
@ -1350,17 +1350,17 @@ void MtpChecker::gotMessage(const MTPmessages_Messages &result) {
} }
auto MtpChecker::parseMessage(const MTPmessages_Messages &result) const auto MtpChecker::parseMessage(const MTPmessages_Messages &result) const
-> base::optional<FileLocation> { -> std::optional<FileLocation> {
const auto message = GetMessagesElement(result); const auto message = GetMessagesElement(result);
if (!message || message->type() != mtpc_message) { if (!message || message->type() != mtpc_message) {
LOG(("Update Error: MTP feed message not found.")); LOG(("Update Error: MTP feed message not found."));
return base::none; return std::nullopt;
} }
return parseText(message->c_message().vmessage.v); return parseText(message->c_message().vmessage.v);
} }
auto MtpChecker::parseText(const QByteArray &text) const auto MtpChecker::parseText(const QByteArray &text) const
-> base::optional<FileLocation> { -> std::optional<FileLocation> {
auto bestAvailableVersion = 0ULL; auto bestAvailableVersion = 0ULL;
auto bestLocation = FileLocation(); auto bestLocation = FileLocation();
const auto accumulate = [&]( const auto accumulate = [&](
@ -1404,7 +1404,7 @@ auto MtpChecker::parseText(const QByteArray &text) const
}; };
const auto result = ParseCommonMap(text, testing(), accumulate); const auto result = ParseCommonMap(text, testing(), accumulate);
if (!result) { if (!result) {
return base::none; return std::nullopt;
} }
return validateLatestLocation(bestAvailableVersion, bestLocation); return validateLatestLocation(bestAvailableVersion, bestLocation);
} }
@ -1430,23 +1430,23 @@ void MtpChecker::gotFile(const MTPmessages_Messages &result) {
} }
auto MtpChecker::parseFile(const MTPmessages_Messages &result) const auto MtpChecker::parseFile(const MTPmessages_Messages &result) const
-> base::optional<ParsedFile> { -> std::optional<ParsedFile> {
const auto message = GetMessagesElement(result); const auto message = GetMessagesElement(result);
if (!message || message->type() != mtpc_message) { if (!message || message->type() != mtpc_message) {
LOG(("Update Error: MTP file message not found.")); LOG(("Update Error: MTP file message not found."));
return base::none; return std::nullopt;
} }
const auto &data = message->c_message(); const auto &data = message->c_message();
if (!data.has_media() if (!data.has_media()
|| data.vmedia.type() != mtpc_messageMediaDocument) { || data.vmedia.type() != mtpc_messageMediaDocument) {
LOG(("Update Error: MTP file media not found.")); LOG(("Update Error: MTP file media not found."));
return base::none; return std::nullopt;
} }
const auto &document = data.vmedia.c_messageMediaDocument(); const auto &document = data.vmedia.c_messageMediaDocument();
if (!document.has_document() if (!document.has_document()
|| document.vdocument.type() != mtpc_document) { || document.vdocument.type() != mtpc_document) {
LOG(("Update Error: MTP file not found.")); LOG(("Update Error: MTP file not found."));
return base::none; return std::nullopt;
} }
const auto &fields = document.vdocument.c_document(); const auto &fields = document.vdocument.c_document();
const auto name = [&] { const auto name = [&] {
@ -1460,12 +1460,12 @@ auto MtpChecker::parseFile(const MTPmessages_Messages &result) const
}(); }();
if (name.isEmpty()) { if (name.isEmpty()) {
LOG(("Update Error: MTP file name not found.")); LOG(("Update Error: MTP file name not found."));
return base::none; return std::nullopt;
} }
const auto size = fields.vsize.v; const auto size = fields.vsize.v;
if (size <= 0) { if (size <= 0) {
LOG(("Update Error: MTP file size is invalid.")); LOG(("Update Error: MTP file size is invalid."));
return base::none; return std::nullopt;
} }
const auto location = MTP_inputDocumentFileLocation( const auto location = MTP_inputDocumentFileLocation(
fields.vid, fields.vid,

View file

@ -250,7 +250,7 @@ void Feed::changeChannelsList(
// After that we restore it. // After that we restore it.
const auto oldLastMessage = base::take(_lastMessage); const auto oldLastMessage = base::take(_lastMessage);
for (const auto channel : add) { for (const auto channel : add) {
_lastMessage = base::none; _lastMessage = std::nullopt;
channel->setFeed(this); channel->setFeed(this);
} }
_lastMessage = oldLastMessage; _lastMessage = oldLastMessage;
@ -282,7 +282,7 @@ void Feed::historyCleared(not_null<History*> history) {
} }
void Feed::recountLastMessage() { void Feed::recountLastMessage() {
_lastMessage = base::none; _lastMessage = std::nullopt;
for (const auto history : _channels) { for (const auto history : _channels) {
if (!history->lastMessageKnown()) { if (!history->lastMessageKnown()) {
_parent->session().api().requestDialogEntry(this); _parent->session().api().requestDialogEntry(this);

View file

@ -103,10 +103,10 @@ private:
QString _name; QString _name;
base::flat_set<QString> _nameWords; base::flat_set<QString> _nameWords;
base::flat_set<QChar> _nameFirstLetters; base::flat_set<QChar> _nameFirstLetters;
base::optional<HistoryItem*> _lastMessage; std::optional<HistoryItem*> _lastMessage;
rpl::variable<MessagePosition> _unreadPosition; rpl::variable<MessagePosition> _unreadPosition;
base::optional<int> _unreadCount; std::optional<int> _unreadCount;
rpl::event_stream<int> _unreadCountChanges; rpl::event_stream<int> _unreadCountChanges;
int _unreadMutedCount = 0; int _unreadMutedCount = 0;

View file

@ -93,7 +93,7 @@ template <typename Range>
void MessagesList::addRange( void MessagesList::addRange(
const Range &messages, const Range &messages,
MessagesRange noSkipRange, MessagesRange noSkipRange,
base::optional<int> count, std::optional<int> count,
bool incrementCount) { bool incrementCount) {
Expects(!count || !incrementCount); Expects(!count || !incrementCount);
@ -119,13 +119,13 @@ void MessagesList::addRange(
void MessagesList::addNew(MessagePosition messageId) { void MessagesList::addNew(MessagePosition messageId) {
auto range = { messageId }; auto range = { messageId };
addRange(range, { messageId, MaxMessagePosition }, base::none, true); addRange(range, { messageId, MaxMessagePosition }, std::nullopt, true);
} }
void MessagesList::addSlice( void MessagesList::addSlice(
std::vector<MessagePosition> &&messageIds, std::vector<MessagePosition> &&messageIds,
MessagesRange noSkipRange, MessagesRange noSkipRange,
base::optional<int> count) { std::optional<int> count) {
addRange(messageIds, noSkipRange, count); addRange(messageIds, noSkipRange, count);
} }
@ -167,7 +167,7 @@ void MessagesList::removeAll(ChannelId channelId) {
void MessagesList::invalidate() { void MessagesList::invalidate() {
_slices.clear(); _slices.clear();
_count = base::none; _count = std::nullopt;
} }
void MessagesList::invalidateBottom() { void MessagesList::invalidateBottom() {
@ -181,7 +181,7 @@ void MessagesList::invalidateBottom() {
}); });
} }
} }
_count = base::none; _count = std::nullopt;
} }
rpl::producer<MessagesResult> MessagesList::query( rpl::producer<MessagesResult> MessagesList::query(
@ -272,10 +272,10 @@ bool MessagesSliceBuilder::applyUpdate(const MessagesSliceUpdate &update) {
} }
auto skippedBefore = (update.range.from == MinMessagePosition) auto skippedBefore = (update.range.from == MinMessagePosition)
? 0 ? 0
: base::optional<int> {}; : std::optional<int> {};
auto skippedAfter = (update.range.till == MaxMessagePosition) auto skippedAfter = (update.range.till == MaxMessagePosition)
? 0 ? 0
: base::optional<int> {}; : std::optional<int> {};
mergeSliceData( mergeSliceData(
update.count, update.count,
needMergeMessages needMergeMessages
@ -331,20 +331,20 @@ bool MessagesSliceBuilder::removeFromChannel(ChannelId channelId) {
++i; ++i;
} }
} }
_skippedBefore = _skippedAfter = base::none; _skippedBefore = _skippedAfter = std::nullopt;
checkInsufficient(); checkInsufficient();
return true; return true;
} }
bool MessagesSliceBuilder::invalidated() { bool MessagesSliceBuilder::invalidated() {
_fullCount = _skippedBefore = _skippedAfter = base::none; _fullCount = _skippedBefore = _skippedAfter = std::nullopt;
_ids.clear(); _ids.clear();
checkInsufficient(); checkInsufficient();
return false; return false;
} }
bool MessagesSliceBuilder::bottomInvalidated() { bool MessagesSliceBuilder::bottomInvalidated() {
_fullCount = _skippedAfter = base::none; _fullCount = _skippedAfter = std::nullopt;
checkInsufficient(); checkInsufficient();
return true; return true;
} }
@ -354,10 +354,10 @@ void MessagesSliceBuilder::checkInsufficient() {
} }
void MessagesSliceBuilder::mergeSliceData( void MessagesSliceBuilder::mergeSliceData(
base::optional<int> count, std::optional<int> count,
const base::flat_set<MessagePosition> &messageIds, const base::flat_set<MessagePosition> &messageIds,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
base::optional<int> skippedAfter) { std::optional<int> skippedAfter) {
if (messageIds.empty()) { if (messageIds.empty()) {
if (count && _fullCount != count) { if (count && _fullCount != count) {
_fullCount = count; _fullCount = count;
@ -388,7 +388,7 @@ void MessagesSliceBuilder::mergeSliceData(
} else if (wasMinId != impossible && _skippedBefore) { } else if (wasMinId != impossible && _skippedBefore) {
adjustSkippedBefore(wasMinId, *_skippedBefore); adjustSkippedBefore(wasMinId, *_skippedBefore);
} else { } else {
_skippedBefore = base::none; _skippedBefore = std::nullopt;
} }
auto adjustSkippedAfter = [&](MessagePosition oldId, int oldSkippedAfter) { auto adjustSkippedAfter = [&](MessagePosition oldId, int oldSkippedAfter) {
@ -402,7 +402,7 @@ void MessagesSliceBuilder::mergeSliceData(
} else if (wasMaxId != impossible && _skippedAfter) { } else if (wasMaxId != impossible && _skippedAfter) {
adjustSkippedAfter(wasMaxId, *_skippedAfter); adjustSkippedAfter(wasMaxId, *_skippedAfter);
} else { } else {
_skippedAfter = base::none; _skippedAfter = std::nullopt;
} }
fillSkippedAndSliceToLimits(); fillSkippedAndSliceToLimits();
} }

View file

@ -93,9 +93,9 @@ constexpr auto UnreadMessagePosition = MessagePosition(
struct MessagesSlice { struct MessagesSlice {
std::vector<FullMsgId> ids; std::vector<FullMsgId> ids;
base::optional<int> skippedBefore; std::optional<int> skippedBefore;
base::optional<int> skippedAfter; std::optional<int> skippedAfter;
base::optional<int> fullCount; std::optional<int> fullCount;
}; };
@ -116,16 +116,16 @@ struct MessagesQuery {
}; };
struct MessagesResult { struct MessagesResult {
base::optional<int> count; std::optional<int> count;
base::optional<int> skippedBefore; std::optional<int> skippedBefore;
base::optional<int> skippedAfter; std::optional<int> skippedAfter;
base::flat_set<MessagePosition> messageIds; base::flat_set<MessagePosition> messageIds;
}; };
struct MessagesSliceUpdate { struct MessagesSliceUpdate {
const base::flat_set<MessagePosition> *messages = nullptr; const base::flat_set<MessagePosition> *messages = nullptr;
MessagesRange range; MessagesRange range;
base::optional<int> count; std::optional<int> count;
}; };
class MessagesList { class MessagesList {
@ -134,7 +134,7 @@ public:
void addSlice( void addSlice(
std::vector<MessagePosition> &&messageIds, std::vector<MessagePosition> &&messageIds,
MessagesRange noSkipRange, MessagesRange noSkipRange,
base::optional<int> count); std::optional<int> count);
void removeOne(MessagePosition messageId); void removeOne(MessagePosition messageId);
void removeAll(ChannelId channelId); void removeAll(ChannelId channelId);
void invalidate(); void invalidate();
@ -178,14 +178,14 @@ private:
void addRange( void addRange(
const Range &messages, const Range &messages,
MessagesRange noSkipRange, MessagesRange noSkipRange,
base::optional<int> count, std::optional<int> count,
bool incrementCount = false); bool incrementCount = false);
MessagesResult queryFromSlice( MessagesResult queryFromSlice(
const MessagesQuery &query, const MessagesQuery &query,
const Slice &slice) const; const Slice &slice) const;
base::optional<int> _count; std::optional<int> _count;
base::flat_set<Slice> _slices; base::flat_set<Slice> _slices;
rpl::event_stream<MessagesSliceUpdate> _sliceUpdated; rpl::event_stream<MessagesSliceUpdate> _sliceUpdated;
@ -234,17 +234,17 @@ private:
void sliceToLimits(); void sliceToLimits();
void mergeSliceData( void mergeSliceData(
base::optional<int> count, std::optional<int> count,
const base::flat_set<MessagePosition> &messageIds, const base::flat_set<MessagePosition> &messageIds,
base::optional<int> skippedBefore = base::none, std::optional<int> skippedBefore = std::nullopt,
base::optional<int> skippedAfter = base::none); std::optional<int> skippedAfter = std::nullopt);
MessagePosition _key; MessagePosition _key;
base::flat_set<MessagePosition> _ids; base::flat_set<MessagePosition> _ids;
MessagesRange _range; MessagesRange _range;
base::optional<int> _fullCount; std::optional<int> _fullCount;
base::optional<int> _skippedBefore; std::optional<int> _skippedBefore;
base::optional<int> _skippedAfter; std::optional<int> _skippedAfter;
int _limitBefore = 0; int _limitBefore = 0;
int _limitAfter = 0; int _limitAfter = 0;

View file

@ -28,24 +28,24 @@ public:
bool change(const MTPDpeerNotifySettings &data); bool change(const MTPDpeerNotifySettings &data);
bool change( bool change(
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts); std::optional<bool> silentPosts);
base::optional<TimeId> muteUntil() const; std::optional<TimeId> muteUntil() const;
base::optional<bool> silentPosts() const; std::optional<bool> silentPosts() const;
MTPinputPeerNotifySettings serialize() const; MTPinputPeerNotifySettings serialize() const;
private: private:
bool change( bool change(
base::optional<int> mute, std::optional<int> mute,
base::optional<QString> sound, std::optional<QString> sound,
base::optional<bool> showPreviews, std::optional<bool> showPreviews,
base::optional<bool> silentPosts); std::optional<bool> silentPosts);
base::optional<TimeId> _mute; std::optional<TimeId> _mute;
base::optional<QString> _sound; std::optional<QString> _sound;
base::optional<bool> _silent; std::optional<bool> _silent;
base::optional<bool> _showPreviews; std::optional<bool> _showPreviews;
}; };
@ -57,18 +57,18 @@ NotifySettingsValue::NotifySettingsValue(
bool NotifySettingsValue::change(const MTPDpeerNotifySettings &data) { bool NotifySettingsValue::change(const MTPDpeerNotifySettings &data) {
return change(data.has_mute_until() return change(data.has_mute_until()
? base::make_optional(data.vmute_until.v) ? base::make_optional(data.vmute_until.v)
: base::none, data.has_sound() : std::nullopt, data.has_sound()
? base::make_optional(qs(data.vsound)) ? base::make_optional(qs(data.vsound))
: base::none, data.has_show_previews() : std::nullopt, data.has_show_previews()
? base::make_optional(mtpIsTrue(data.vshow_previews)) ? base::make_optional(mtpIsTrue(data.vshow_previews))
: base::none, data.has_silent() : std::nullopt, data.has_silent()
? base::make_optional(mtpIsTrue(data.vsilent)) ? base::make_optional(mtpIsTrue(data.vsilent))
: base::none); : std::nullopt);
} }
bool NotifySettingsValue::change( bool NotifySettingsValue::change(
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts) { std::optional<bool> silentPosts) {
const auto now = unixtime(); const auto now = unixtime();
const auto notMuted = muteForSeconds const auto notMuted = muteForSeconds
? !(*muteForSeconds) ? !(*muteForSeconds)
@ -92,10 +92,10 @@ bool NotifySettingsValue::change(
} }
bool NotifySettingsValue::change( bool NotifySettingsValue::change(
base::optional<int> mute, std::optional<int> mute,
base::optional<QString> sound, std::optional<QString> sound,
base::optional<bool> showPreviews, std::optional<bool> showPreviews,
base::optional<bool> silentPosts) { std::optional<bool> silentPosts) {
if (_mute == mute if (_mute == mute
&& _sound == sound && _sound == sound
&& _showPreviews == showPreviews && _showPreviews == showPreviews
@ -109,11 +109,11 @@ bool NotifySettingsValue::change(
return true; return true;
} }
base::optional<TimeId> NotifySettingsValue::muteUntil() const { std::optional<TimeId> NotifySettingsValue::muteUntil() const {
return _mute; return _mute;
} }
base::optional<bool> NotifySettingsValue::silentPosts() const { std::optional<bool> NotifySettingsValue::silentPosts() const {
return _silent; return _silent;
} }
@ -157,8 +157,8 @@ bool NotifySettings::change(const MTPPeerNotifySettings &settings) {
} }
bool NotifySettings::change( bool NotifySettings::change(
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts) { std::optional<bool> silentPosts) {
if (!muteForSeconds && !silentPosts) { if (!muteForSeconds && !silentPosts) {
return false; return false;
} else if (_value) { } else if (_value) {
@ -178,20 +178,20 @@ bool NotifySettings::change(
MTPstring())); MTPstring()));
} }
base::optional<TimeId> NotifySettings::muteUntil() const { std::optional<TimeId> NotifySettings::muteUntil() const {
return _value return _value
? _value->muteUntil() ? _value->muteUntil()
: base::none; : std::nullopt;
} }
bool NotifySettings::settingsUnknown() const { bool NotifySettings::settingsUnknown() const {
return !_known; return !_known;
} }
base::optional<bool> NotifySettings::silentPosts() const { std::optional<bool> NotifySettings::silentPosts() const {
return _value return _value
? _value->silentPosts() ? _value->silentPosts()
: base::none; : std::nullopt;
} }
MTPinputPeerNotifySettings NotifySettings::serialize() const { MTPinputPeerNotifySettings NotifySettings::serialize() const {

View file

@ -19,12 +19,12 @@ public:
bool change(const MTPPeerNotifySettings &settings); bool change(const MTPPeerNotifySettings &settings);
bool change( bool change(
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts); std::optional<bool> silentPosts);
bool settingsUnknown() const; bool settingsUnknown() const;
base::optional<TimeId> muteUntil() const; std::optional<TimeId> muteUntil() const;
base::optional<bool> silentPosts() const; std::optional<bool> silentPosts() const;
MTPinputPeerNotifySettings serialize() const; MTPinputPeerNotifySettings serialize() const;
~NotifySettings(); ~NotifySettings();

View file

@ -68,21 +68,21 @@ public:
bool isVerified() const; bool isVerified() const;
bool isMegagroup() const; bool isMegagroup() const;
base::optional<TimeId> notifyMuteUntil() const { std::optional<TimeId> notifyMuteUntil() const {
return _notify.muteUntil(); return _notify.muteUntil();
} }
bool notifyChange(const MTPPeerNotifySettings &settings) { bool notifyChange(const MTPPeerNotifySettings &settings) {
return _notify.change(settings); return _notify.change(settings);
} }
bool notifyChange( bool notifyChange(
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts) { std::optional<bool> silentPosts) {
return _notify.change(muteForSeconds, silentPosts); return _notify.change(muteForSeconds, silentPosts);
} }
bool notifySettingsUnknown() const { bool notifySettingsUnknown() const {
return _notify.settingsUnknown(); return _notify.settingsUnknown();
} }
base::optional<bool> notifySilentPosts() const { std::optional<bool> notifySilentPosts() const {
return _notify.silentPosts(); return _notify.silentPosts();
} }
MTPinputPeerNotifySettings notifySerialize() const { MTPinputPeerNotifySettings notifySerialize() const {

View file

@ -39,7 +39,7 @@ int OnlinePhraseChangeInSeconds(TimeId online, TimeId now) {
return std::max(static_cast<TimeId>(nowFull.secsTo(tomorrow)), 0); return std::max(static_cast<TimeId>(nowFull.secsTo(tomorrow)), 0);
} }
base::optional<QString> OnlineTextSpecial(not_null<UserData*> user) { std::optional<QString> OnlineTextSpecial(not_null<UserData*> user) {
if (isNotificationsUser(user->id)) { if (isNotificationsUser(user->id)) {
return lang(lng_status_service_notifications); return lang(lng_status_service_notifications);
} else if (user->botInfo) { } else if (user->botInfo) {
@ -47,10 +47,10 @@ base::optional<QString> OnlineTextSpecial(not_null<UserData*> user) {
} else if (isServiceUser(user->id)) { } else if (isServiceUser(user->id)) {
return lang(lng_status_support); return lang(lng_status_support);
} }
return base::none; return std::nullopt;
} }
base::optional<QString> OnlineTextCommon(TimeId online, TimeId now) { std::optional<QString> OnlineTextCommon(TimeId online, TimeId now) {
if (online <= 0) { if (online <= 0) {
switch (online) { switch (online) {
case 0: case 0:
@ -65,7 +65,7 @@ base::optional<QString> OnlineTextCommon(TimeId online, TimeId now) {
} else if (online > now) { } else if (online > now) {
return lang(lng_status_online); return lang(lng_status_online);
} }
return base::none; return std::nullopt;
} }
} // namespace } // namespace

View file

@ -180,7 +180,7 @@ SearchController::CacheEntry::CacheEntry(const Query &query)
: peerData(App::peer(query.peerId)) : peerData(App::peer(query.peerId))
, migratedData(query.migratedPeerId , migratedData(query.migratedPeerId
? base::make_optional(Data(App::peer(query.migratedPeerId))) ? base::make_optional(Data(App::peer(query.migratedPeerId)))
: base::none) { : std::nullopt) {
} }
bool SearchController::hasInCache(const Query &query) const { bool SearchController::hasInCache(const Query &query) const {

View file

@ -64,7 +64,7 @@ public:
struct SavedState { struct SavedState {
Query query; Query query;
IdsList peerList; IdsList peerList;
base::optional<IdsList> migratedList; std::optional<IdsList> migratedList;
}; };
void setQuery(const Query &query); void setQuery(const Query &query);
@ -100,7 +100,7 @@ private:
CacheEntry(const Query &query); CacheEntry(const Query &query);
Data peerData; Data peerData;
base::optional<Data> migratedData; std::optional<Data> migratedData;
}; };
struct CacheLess { struct CacheLess {

View file

@ -1842,8 +1842,8 @@ void Session::applyNotifySetting(
void Session::updateNotifySettings( void Session::updateNotifySettings(
not_null<PeerData*> peer, not_null<PeerData*> peer,
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts) { std::optional<bool> silentPosts) {
if (peer->notifyChange(muteForSeconds, silentPosts)) { if (peer->notifyChange(muteForSeconds, silentPosts)) {
updateNotifySettingsLocal(peer); updateNotifySettingsLocal(peer);
_session->api().updateNotifySettingsDelayed(peer); _session->api().updateNotifySettingsDelayed(peer);

View file

@ -396,8 +396,8 @@ public:
const MTPPeerNotifySettings &settings); const MTPPeerNotifySettings &settings);
void updateNotifySettings( void updateNotifySettings(
not_null<PeerData*> peer, not_null<PeerData*> peer,
base::optional<int> muteForSeconds, std::optional<int> muteForSeconds,
base::optional<bool> silentPosts = base::none); std::optional<bool> silentPosts = std::nullopt);
bool notifyIsMuted( bool notifyIsMuted(
not_null<const PeerData*> peer, not_null<const PeerData*> peer,
TimeMs *changesIn = nullptr) const; TimeMs *changesIn = nullptr) const;

View file

@ -30,7 +30,7 @@ using Type = Storage::SharedMediaType;
} // namespace } // namespace
base::optional<Storage::SharedMediaType> SharedMediaOverviewType( std::optional<Storage::SharedMediaType> SharedMediaOverviewType(
Storage::SharedMediaType type) { Storage::SharedMediaType type) {
switch (type) { switch (type) {
case Type::Photo: case Type::Photo:
@ -40,7 +40,7 @@ base::optional<Storage::SharedMediaType> SharedMediaOverviewType(
case Type::VoiceFile: case Type::VoiceFile:
case Type::Link: return type; case Type::Link: return type;
} }
return base::none; return std::nullopt;
} }
void SharedMediaShowOverview( void SharedMediaShowOverview(
@ -177,7 +177,7 @@ SharedMediaWithLastSlice::SharedMediaWithLastSlice(Key key)
SharedMediaWithLastSlice::SharedMediaWithLastSlice( SharedMediaWithLastSlice::SharedMediaWithLastSlice(
Key key, Key key,
SparseIdsMergedSlice slice, SparseIdsMergedSlice slice,
base::optional<SparseIdsMergedSlice> ending) std::optional<SparseIdsMergedSlice> ending)
: _key(key) : _key(key)
, _slice(std::move(slice)) , _slice(std::move(slice))
, _ending(std::move(ending)) , _ending(std::move(ending))
@ -187,21 +187,21 @@ SharedMediaWithLastSlice::SharedMediaWithLastSlice(
: false) { : false) {
} }
base::optional<int> SharedMediaWithLastSlice::fullCount() const { std::optional<int> SharedMediaWithLastSlice::fullCount() const {
return Add( return Add(
_slice.fullCount(), _slice.fullCount(),
_isolatedLastPhoto | [](bool isolated) { return isolated ? 1 : 0; }); _isolatedLastPhoto | [](bool isolated) { return isolated ? 1 : 0; });
} }
base::optional<int> SharedMediaWithLastSlice::skippedBeforeImpl() const { std::optional<int> SharedMediaWithLastSlice::skippedBeforeImpl() const {
return _slice.skippedBefore(); return _slice.skippedBefore();
} }
base::optional<int> SharedMediaWithLastSlice::skippedBefore() const { std::optional<int> SharedMediaWithLastSlice::skippedBefore() const {
return _reversed ? skippedAfterImpl() : skippedBeforeImpl(); return _reversed ? skippedAfterImpl() : skippedBeforeImpl();
} }
base::optional<int> SharedMediaWithLastSlice::skippedAfterImpl() const { std::optional<int> SharedMediaWithLastSlice::skippedAfterImpl() const {
return isolatedInSlice() return isolatedInSlice()
? Add( ? Add(
_slice.skippedAfter(), _slice.skippedAfter(),
@ -209,21 +209,21 @@ base::optional<int> SharedMediaWithLastSlice::skippedAfterImpl() const {
: (lastPhotoSkip() | [](int) { return 0; }); : (lastPhotoSkip() | [](int) { return 0; });
} }
base::optional<int> SharedMediaWithLastSlice::skippedAfter() const { std::optional<int> SharedMediaWithLastSlice::skippedAfter() const {
return _reversed ? skippedBeforeImpl() : skippedAfterImpl(); return _reversed ? skippedBeforeImpl() : skippedAfterImpl();
} }
base::optional<int> SharedMediaWithLastSlice::indexOfImpl(Value value) const { std::optional<int> SharedMediaWithLastSlice::indexOfImpl(Value value) const {
return base::get_if<FullMsgId>(&value) return base::get_if<FullMsgId>(&value)
? _slice.indexOf(*base::get_if<FullMsgId>(&value)) ? _slice.indexOf(*base::get_if<FullMsgId>(&value))
: (isolatedInSlice() : (isolatedInSlice()
|| !_lastPhotoId || !_lastPhotoId
|| (*base::get_if<not_null<PhotoData*>>(&value))->id != *_lastPhotoId) || (*base::get_if<not_null<PhotoData*>>(&value))->id != *_lastPhotoId)
? base::none ? std::nullopt
: Add(_slice.size() - 1, lastPhotoSkip()); : Add(_slice.size() - 1, lastPhotoSkip());
} }
base::optional<int> SharedMediaWithLastSlice::indexOf(Value value) const { std::optional<int> SharedMediaWithLastSlice::indexOf(Value value) const {
const auto result = indexOfImpl(value); const auto result = indexOfImpl(value);
if (result && (*result < 0 || *result >= size())) { if (result && (*result < 0 || *result >= size())) {
// Should not happen. // Should not happen.
@ -296,7 +296,7 @@ SharedMediaWithLastSlice::Value SharedMediaWithLastSlice::operator[](int index)
: Value(Auth().data().photo(*_lastPhotoId)); : Value(Auth().data().photo(*_lastPhotoId));
} }
base::optional<int> SharedMediaWithLastSlice::distance( std::optional<int> SharedMediaWithLastSlice::distance(
const Key &a, const Key &a,
const Key &b) const { const Key &b) const {
if (auto i = indexOf(ComputeId(a))) { if (auto i = indexOf(ComputeId(a))) {
@ -304,29 +304,29 @@ base::optional<int> SharedMediaWithLastSlice::distance(
return *j - *i; return *j - *i;
} }
} }
return base::none; return std::nullopt;
} }
void SharedMediaWithLastSlice::reverse() { void SharedMediaWithLastSlice::reverse() {
_reversed = !_reversed; _reversed = !_reversed;
} }
base::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId( std::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId(
PeerId peerId) { PeerId peerId) {
if (auto peer = App::peerLoaded(peerId)) { if (auto peer = App::peerLoaded(peerId)) {
return peer->userpicPhotoUnknown() return peer->userpicPhotoUnknown()
? base::none ? std::nullopt
: base::make_optional(peer->userpicPhotoId()); : base::make_optional(peer->userpicPhotoId());
} }
return base::none; return std::nullopt;
} }
base::optional<bool> SharedMediaWithLastSlice::IsLastIsolated( std::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
const SparseIdsMergedSlice &slice, const SparseIdsMergedSlice &slice,
const base::optional<SparseIdsMergedSlice> &ending, const std::optional<SparseIdsMergedSlice> &ending,
base::optional<PhotoId> lastPeerPhotoId) { std::optional<PhotoId> lastPeerPhotoId) {
if (!lastPeerPhotoId) { if (!lastPeerPhotoId) {
return base::none; return std::nullopt;
} else if (!*lastPeerPhotoId) { } else if (!*lastPeerPhotoId) {
return false; return false;
} }
@ -338,12 +338,12 @@ base::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
| [&](PhotoId photoId) { return *lastPeerPhotoId != photoId; }; | [&](PhotoId photoId) { return *lastPeerPhotoId != photoId; };
} }
base::optional<FullMsgId> SharedMediaWithLastSlice::LastFullMsgId( std::optional<FullMsgId> SharedMediaWithLastSlice::LastFullMsgId(
const SparseIdsMergedSlice &slice) { const SparseIdsMergedSlice &slice) {
if (slice.fullCount() == 0) { if (slice.fullCount() == 0) {
return FullMsgId(); return FullMsgId();
} else if (slice.size() == 0 || slice.skippedAfter() != 0) { } else if (slice.size() == 0 || slice.skippedAfter() != 0) {
return base::none; return std::nullopt;
} }
return slice[slice.size() - 1]; return slice[slice.size() - 1];
} }
@ -364,7 +364,7 @@ rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
consumer.put_next(SharedMediaWithLastSlice( consumer.put_next(SharedMediaWithLastSlice(
key, key,
std::move(update), std::move(update),
base::none)); std::nullopt));
}); });
} }
return rpl::combine( return rpl::combine(

View file

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/weak_ptr.h" #include "base/weak_ptr.h"
#include "data/data_sparse_ids.h" #include "data/data_sparse_ids.h"
base::optional<Storage::SharedMediaType> SharedMediaOverviewType( std::optional<Storage::SharedMediaType> SharedMediaOverviewType(
Storage::SharedMediaType type); Storage::SharedMediaType type);
void SharedMediaShowOverview( void SharedMediaShowOverview(
Storage::SharedMediaType type, Storage::SharedMediaType type,
@ -93,15 +93,15 @@ public:
SharedMediaWithLastSlice( SharedMediaWithLastSlice(
Key key, Key key,
SparseIdsMergedSlice slice, SparseIdsMergedSlice slice,
base::optional<SparseIdsMergedSlice> ending); std::optional<SparseIdsMergedSlice> ending);
base::optional<int> fullCount() const; std::optional<int> fullCount() const;
base::optional<int> skippedBefore() const; std::optional<int> skippedBefore() const;
base::optional<int> skippedAfter() const; std::optional<int> skippedAfter() const;
base::optional<int> indexOf(Value fullId) const; std::optional<int> indexOf(Value fullId) const;
int size() const; int size() const;
Value operator[](int index) const; Value operator[](int index) const;
base::optional<int> distance(const Key &a, const Key &b) const; std::optional<int> distance(const Key &a, const Key &b) const;
void reverse(); void reverse();
@ -123,23 +123,23 @@ public:
} }
private: private:
static base::optional<SparseIdsMergedSlice> EndingSlice(const Key &key) { static std::optional<SparseIdsMergedSlice> EndingSlice(const Key &key) {
return base::get_if<MessageId>(&key.universalId) return base::get_if<MessageId>(&key.universalId)
? base::make_optional(SparseIdsMergedSlice(EndingKey(key))) ? base::make_optional(SparseIdsMergedSlice(EndingKey(key)))
: base::none; : std::nullopt;
} }
static base::optional<PhotoId> LastPeerPhotoId(PeerId peerId); static std::optional<PhotoId> LastPeerPhotoId(PeerId peerId);
static base::optional<bool> IsLastIsolated( static std::optional<bool> IsLastIsolated(
const SparseIdsMergedSlice &slice, const SparseIdsMergedSlice &slice,
const base::optional<SparseIdsMergedSlice> &ending, const std::optional<SparseIdsMergedSlice> &ending,
base::optional<PhotoId> lastPeerPhotoId); std::optional<PhotoId> lastPeerPhotoId);
static base::optional<FullMsgId> LastFullMsgId( static std::optional<FullMsgId> LastFullMsgId(
const SparseIdsMergedSlice &slice); const SparseIdsMergedSlice &slice);
static base::optional<int> Add( static std::optional<int> Add(
const base::optional<int> &a, const std::optional<int> &a,
const base::optional<int> &b) { const std::optional<int> &b) {
return (a && b) ? base::make_optional(*a + *b) : base::none; return (a && b) ? base::make_optional(*a + *b) : std::nullopt;
} }
static Value ComputeId(PeerId peerId, MsgId msgId) { static Value ComputeId(PeerId peerId, MsgId msgId) {
return FullMsgId( return FullMsgId(
@ -158,20 +158,20 @@ private:
bool isolatedInSlice() const { bool isolatedInSlice() const {
return (_slice.skippedAfter() != 0); return (_slice.skippedAfter() != 0);
} }
base::optional<int> lastPhotoSkip() const { std::optional<int> lastPhotoSkip() const {
return _isolatedLastPhoto return _isolatedLastPhoto
| [](bool isolated) { return isolated ? 1 : 0; }; | [](bool isolated) { return isolated ? 1 : 0; };
} }
base::optional<int> skippedBeforeImpl() const; std::optional<int> skippedBeforeImpl() const;
base::optional<int> skippedAfterImpl() const; std::optional<int> skippedAfterImpl() const;
base::optional<int> indexOfImpl(Value fullId) const; std::optional<int> indexOfImpl(Value fullId) const;
Key _key; Key _key;
SparseIdsMergedSlice _slice; SparseIdsMergedSlice _slice;
base::optional<SparseIdsMergedSlice> _ending; std::optional<SparseIdsMergedSlice> _ending;
base::optional<PhotoId> _lastPhotoId; std::optional<PhotoId> _lastPhotoId;
base::optional<bool> _isolatedLastPhoto; std::optional<bool> _isolatedLastPhoto;
bool _reversed = false; bool _reversed = false;
}; };

View file

@ -13,9 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
SparseIdsSlice::SparseIdsSlice( SparseIdsSlice::SparseIdsSlice(
const base::flat_set<MsgId> &ids, const base::flat_set<MsgId> &ids,
MsgRange range, MsgRange range,
base::optional<int> fullCount, std::optional<int> fullCount,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
base::optional<int> skippedAfter) std::optional<int> skippedAfter)
: _ids(ids) : _ids(ids)
, _range(range) , _range(range)
, _fullCount(fullCount) , _fullCount(fullCount)
@ -23,12 +23,12 @@ SparseIdsSlice::SparseIdsSlice(
, _skippedAfter(skippedAfter) { , _skippedAfter(skippedAfter) {
} }
base::optional<int> SparseIdsSlice::indexOf(MsgId msgId) const { std::optional<int> SparseIdsSlice::indexOf(MsgId msgId) const {
auto it = _ids.find(msgId); auto it = _ids.find(msgId);
if (it != _ids.end()) { if (it != _ids.end()) {
return (it - _ids.begin()); return (it - _ids.begin());
} }
return base::none; return std::nullopt;
} }
MsgId SparseIdsSlice::operator[](int index) const { MsgId SparseIdsSlice::operator[](int index) const {
@ -37,7 +37,7 @@ MsgId SparseIdsSlice::operator[](int index) const {
return *(_ids.begin() + index); return *(_ids.begin() + index);
} }
base::optional<int> SparseIdsSlice::distance( std::optional<int> SparseIdsSlice::distance(
MsgId a, MsgId a,
MsgId b) const { MsgId b) const {
if (auto i = indexOf(a)) { if (auto i = indexOf(a)) {
@ -45,14 +45,14 @@ base::optional<int> SparseIdsSlice::distance(
return *j - *i; return *j - *i;
} }
} }
return base::none; return std::nullopt;
} }
base::optional<MsgId> SparseIdsSlice::nearest(MsgId msgId) const { std::optional<MsgId> SparseIdsSlice::nearest(MsgId msgId) const {
if (auto it = ranges::lower_bound(_ids, msgId); it != _ids.end()) { if (auto it = ranges::lower_bound(_ids, msgId); it != _ids.end()) {
return *it; return *it;
} else if (_ids.empty()) { } else if (_ids.empty()) {
return base::none; return std::nullopt;
} }
return _ids.back(); return _ids.back();
} }
@ -67,19 +67,19 @@ SparseIdsMergedSlice::SparseIdsMergedSlice(Key key)
SparseIdsMergedSlice::SparseIdsMergedSlice( SparseIdsMergedSlice::SparseIdsMergedSlice(
Key key, Key key,
SparseIdsSlice part, SparseIdsSlice part,
base::optional<SparseIdsSlice> migrated) std::optional<SparseIdsSlice> migrated)
: _key(key) : _key(key)
, _part(std::move(part)) , _part(std::move(part))
, _migrated(std::move(migrated)) { , _migrated(std::move(migrated)) {
} }
base::optional<int> SparseIdsMergedSlice::fullCount() const { std::optional<int> SparseIdsMergedSlice::fullCount() const {
return Add( return Add(
_part.fullCount(), _part.fullCount(),
_migrated ? _migrated->fullCount() : 0); _migrated ? _migrated->fullCount() : 0);
} }
base::optional<int> SparseIdsMergedSlice::skippedBefore() const { std::optional<int> SparseIdsMergedSlice::skippedBefore() const {
return Add( return Add(
isolatedInMigrated() ? 0 : _part.skippedBefore(), isolatedInMigrated() ? 0 : _part.skippedBefore(),
_migrated _migrated
@ -90,22 +90,22 @@ base::optional<int> SparseIdsMergedSlice::skippedBefore() const {
); );
} }
base::optional<int> SparseIdsMergedSlice::skippedAfter() const { std::optional<int> SparseIdsMergedSlice::skippedAfter() const {
return Add( return Add(
isolatedInMigrated() ? _part.fullCount() : _part.skippedAfter(), isolatedInMigrated() ? _part.fullCount() : _part.skippedAfter(),
isolatedInPart() ? 0 : _migrated->skippedAfter() isolatedInPart() ? 0 : _migrated->skippedAfter()
); );
} }
base::optional<int> SparseIdsMergedSlice::indexOf( std::optional<int> SparseIdsMergedSlice::indexOf(
FullMsgId fullId) const { FullMsgId fullId) const {
return isFromPart(fullId) return isFromPart(fullId)
? (_part.indexOf(fullId.msg) | func::add(migratedSize())) ? (_part.indexOf(fullId.msg) | func::add(migratedSize()))
: isolatedInPart() : isolatedInPart()
? base::none ? std::nullopt
: isFromMigrated(fullId) : isFromMigrated(fullId)
? _migrated->indexOf(fullId.msg) ? _migrated->indexOf(fullId.msg)
: base::none; : std::nullopt;
} }
int SparseIdsMergedSlice::size() const { int SparseIdsMergedSlice::size() const {
@ -125,7 +125,7 @@ FullMsgId SparseIdsMergedSlice::operator[](int index) const {
return ComputeId(_key.peerId, _part[index]); return ComputeId(_key.peerId, _part[index]);
} }
base::optional<int> SparseIdsMergedSlice::distance( std::optional<int> SparseIdsMergedSlice::distance(
const Key &a, const Key &a,
const Key &b) const { const Key &b) const {
if (auto i = indexOf(ComputeId(a))) { if (auto i = indexOf(ComputeId(a))) {
@ -133,11 +133,11 @@ base::optional<int> SparseIdsMergedSlice::distance(
return *j - *i; return *j - *i;
} }
} }
return base::none; return std::nullopt;
} }
auto SparseIdsMergedSlice::nearest( auto SparseIdsMergedSlice::nearest(
UniversalMsgId id) const -> base::optional<FullMsgId> { UniversalMsgId id) const -> std::optional<FullMsgId> {
auto convertFromPartNearest = [&](MsgId result) { auto convertFromPartNearest = [&](MsgId result) {
return ComputeId(_key.peerId, result); return ComputeId(_key.peerId, result);
}; };
@ -149,18 +149,18 @@ auto SparseIdsMergedSlice::nearest(
return partNearestId return partNearestId
| convertFromPartNearest; | convertFromPartNearest;
} else if (isolatedInPart()) { } else if (isolatedInPart()) {
return base::none; return std::nullopt;
} }
return _migrated->nearest(ServerMaxMsgId - 1) return _migrated->nearest(ServerMaxMsgId - 1)
| convertFromMigratedNearest; | convertFromMigratedNearest;
} }
if (auto migratedNearestId = _migrated if (auto migratedNearestId = _migrated
? _migrated->nearest(id + ServerMaxMsgId) ? _migrated->nearest(id + ServerMaxMsgId)
: base::none) { : std::nullopt) {
return migratedNearestId return migratedNearestId
| convertFromMigratedNearest; | convertFromMigratedNearest;
} else if (isolatedInMigrated()) { } else if (isolatedInMigrated()) {
return base::none; return std::nullopt;
} }
return _part.nearest(0) return _part.nearest(0)
| convertFromPartNearest; | convertFromPartNearest;
@ -201,10 +201,10 @@ bool SparseIdsSliceBuilder::applyUpdate(
} }
auto skippedBefore = (update.range.from == 0) auto skippedBefore = (update.range.from == 0)
? 0 ? 0
: base::optional<int> {}; : std::optional<int> {};
auto skippedAfter = (update.range.till == ServerMaxMsgId) auto skippedAfter = (update.range.till == ServerMaxMsgId)
? 0 ? 0
: base::optional<int> {}; : std::optional<int> {};
mergeSliceData( mergeSliceData(
update.count, update.count,
needMergeMessages needMergeMessages
@ -253,7 +253,7 @@ bool SparseIdsSliceBuilder::removeAll() {
} }
bool SparseIdsSliceBuilder::invalidateBottom() { bool SparseIdsSliceBuilder::invalidateBottom() {
_fullCount = _skippedAfter = base::none; _fullCount = _skippedAfter = std::nullopt;
if (_range.till == ServerMaxMsgId) { if (_range.till == ServerMaxMsgId) {
_range.till = _ids.empty() ? _range.from : _ids.back(); _range.till = _ids.empty() ? _range.from : _ids.back();
} }
@ -266,10 +266,10 @@ void SparseIdsSliceBuilder::checkInsufficient() {
} }
void SparseIdsSliceBuilder::mergeSliceData( void SparseIdsSliceBuilder::mergeSliceData(
base::optional<int> count, std::optional<int> count,
const base::flat_set<MsgId> &messageIds, const base::flat_set<MsgId> &messageIds,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
base::optional<int> skippedAfter) { std::optional<int> skippedAfter) {
if (messageIds.empty()) { if (messageIds.empty()) {
if (count && _fullCount != count) { if (count && _fullCount != count) {
_fullCount = count; _fullCount = count;
@ -299,7 +299,7 @@ void SparseIdsSliceBuilder::mergeSliceData(
} else if (wasMinId >= 0 && _skippedBefore) { } else if (wasMinId >= 0 && _skippedBefore) {
adjustSkippedBefore(wasMinId, *_skippedBefore); adjustSkippedBefore(wasMinId, *_skippedBefore);
} else { } else {
_skippedBefore = base::none; _skippedBefore = std::nullopt;
} }
auto adjustSkippedAfter = [&](MsgId oldId, int oldSkippedAfter) { auto adjustSkippedAfter = [&](MsgId oldId, int oldSkippedAfter) {
@ -313,7 +313,7 @@ void SparseIdsSliceBuilder::mergeSliceData(
} else if (wasMaxId >= 0 && _skippedAfter) { } else if (wasMaxId >= 0 && _skippedAfter) {
adjustSkippedAfter(wasMaxId, *_skippedAfter); adjustSkippedAfter(wasMaxId, *_skippedAfter);
} else { } else {
_skippedAfter = base::none; _skippedAfter = std::nullopt;
} }
fillSkippedAndSliceToLimits(); fillSkippedAndSliceToLimits();
} }
@ -420,7 +420,7 @@ rpl::producer<SparseIdsMergedSlice> SparseIdsMergedSlice::CreateViewer(
consumer.put_next(SparseIdsMergedSlice( consumer.put_next(SparseIdsMergedSlice(
key, key,
std::move(part), std::move(part),
base::none)); std::nullopt));
}); });
} }
auto migratedViewer = simpleViewer( auto migratedViewer = simpleViewer(

View file

@ -22,25 +22,25 @@ public:
SparseIdsSlice( SparseIdsSlice(
const base::flat_set<MsgId> &ids, const base::flat_set<MsgId> &ids,
MsgRange range, MsgRange range,
base::optional<int> fullCount, std::optional<int> fullCount,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
base::optional<int> skippedAfter); std::optional<int> skippedAfter);
base::optional<int> fullCount() const { return _fullCount; } std::optional<int> fullCount() const { return _fullCount; }
base::optional<int> skippedBefore() const { return _skippedBefore; } std::optional<int> skippedBefore() const { return _skippedBefore; }
base::optional<int> skippedAfter() const { return _skippedAfter; } std::optional<int> skippedAfter() const { return _skippedAfter; }
base::optional<int> indexOf(MsgId msgId) const; std::optional<int> indexOf(MsgId msgId) const;
int size() const { return _ids.size(); } int size() const { return _ids.size(); }
MsgId operator[](int index) const; MsgId operator[](int index) const;
base::optional<int> distance(MsgId a, MsgId b) const; std::optional<int> distance(MsgId a, MsgId b) const;
base::optional<MsgId> nearest(MsgId msgId) const; std::optional<MsgId> nearest(MsgId msgId) const;
private: private:
base::flat_set<MsgId> _ids; base::flat_set<MsgId> _ids;
MsgRange _range; MsgRange _range;
base::optional<int> _fullCount; std::optional<int> _fullCount;
base::optional<int> _skippedBefore; std::optional<int> _skippedBefore;
base::optional<int> _skippedAfter; std::optional<int> _skippedAfter;
}; };
@ -76,16 +76,16 @@ public:
SparseIdsMergedSlice( SparseIdsMergedSlice(
Key key, Key key,
SparseIdsSlice part, SparseIdsSlice part,
base::optional<SparseIdsSlice> migrated); std::optional<SparseIdsSlice> migrated);
base::optional<int> fullCount() const; std::optional<int> fullCount() const;
base::optional<int> skippedBefore() const; std::optional<int> skippedBefore() const;
base::optional<int> skippedAfter() const; std::optional<int> skippedAfter() const;
base::optional<int> indexOf(FullMsgId fullId) const; std::optional<int> indexOf(FullMsgId fullId) const;
int size() const; int size() const;
FullMsgId operator[](int index) const; FullMsgId operator[](int index) const;
base::optional<int> distance(const Key &a, const Key &b) const; std::optional<int> distance(const Key &a, const Key &b) const;
base::optional<FullMsgId> nearest(UniversalMsgId id) const; std::optional<FullMsgId> nearest(UniversalMsgId id) const;
using SimpleViewerFunction = rpl::producer<SparseIdsSlice>( using SimpleViewerFunction = rpl::producer<SparseIdsSlice>(
PeerId peerId, PeerId peerId,
@ -107,10 +107,10 @@ private:
? (ServerMaxMsgId + key.universalId) ? (ServerMaxMsgId + key.universalId)
: (key.universalId > 0) ? (ServerMaxMsgId - 1) : 0; : (key.universalId > 0) ? (ServerMaxMsgId - 1) : 0;
} }
static base::optional<SparseIdsSlice> MigratedSlice(const Key &key) { static std::optional<SparseIdsSlice> MigratedSlice(const Key &key) {
return key.migratedPeerId return key.migratedPeerId
? base::make_optional(SparseIdsSlice()) ? base::make_optional(SparseIdsSlice())
: base::none; : std::nullopt;
} }
static bool IsFromSlice(PeerId peerId, FullMsgId fullId) { static bool IsFromSlice(PeerId peerId, FullMsgId fullId) {
@ -128,10 +128,10 @@ private:
? ComputeId(key.peerId, key.universalId) ? ComputeId(key.peerId, key.universalId)
: ComputeId(key.migratedPeerId, ServerMaxMsgId + key.universalId); : ComputeId(key.migratedPeerId, ServerMaxMsgId + key.universalId);
} }
static base::optional<int> Add( static std::optional<int> Add(
const base::optional<int> &a, const std::optional<int> &a,
const base::optional<int> &b) { const std::optional<int> &b) {
return (a && b) ? base::make_optional(*a + *b) : base::none; return (a && b) ? base::make_optional(*a + *b) : std::nullopt;
} }
bool isFromPart(FullMsgId fullId) const { bool isFromPart(FullMsgId fullId) const {
@ -156,7 +156,7 @@ private:
Key _key; Key _key;
SparseIdsSlice _part; SparseIdsSlice _part;
base::optional<SparseIdsSlice> _migrated; std::optional<SparseIdsSlice> _migrated;
}; };
@ -200,17 +200,17 @@ private:
void sliceToLimits(); void sliceToLimits();
void mergeSliceData( void mergeSliceData(
base::optional<int> count, std::optional<int> count,
const base::flat_set<MsgId> &messageIds, const base::flat_set<MsgId> &messageIds,
base::optional<int> skippedBefore = base::none, std::optional<int> skippedBefore = std::nullopt,
base::optional<int> skippedAfter = base::none); std::optional<int> skippedAfter = std::nullopt);
Key _key; Key _key;
base::flat_set<MsgId> _ids; base::flat_set<MsgId> _ids;
MsgRange _range; MsgRange _range;
base::optional<int> _fullCount; std::optional<int> _fullCount;
base::optional<int> _skippedBefore; std::optional<int> _skippedBefore;
base::optional<int> _skippedAfter; std::optional<int> _skippedAfter;
int _limitBefore = 0; int _limitBefore = 0;
int _limitAfter = 0; int _limitAfter = 0;

View file

@ -29,16 +29,16 @@ public:
private: private:
void mergeSliceData( void mergeSliceData(
base::optional<int> count, std::optional<int> count,
const std::deque<PhotoId> &photoIds, const std::deque<PhotoId> &photoIds,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
int skippedAfter); int skippedAfter);
void sliceToLimits(); void sliceToLimits();
Key _key; Key _key;
std::deque<PhotoId> _ids; std::deque<PhotoId> _ids;
base::optional<int> _fullCount; std::optional<int> _fullCount;
base::optional<int> _skippedBefore; std::optional<int> _skippedBefore;
int _skippedAfter = 0; int _skippedAfter = 0;
int _limitBefore = 0; int _limitBefore = 0;
int _limitAfter = 0; int _limitAfter = 0;
@ -51,17 +51,17 @@ UserPhotosSlice::UserPhotosSlice(Key key)
: UserPhotosSlice( : UserPhotosSlice(
key, key,
{}, {},
base::none, std::nullopt,
base::none, std::nullopt,
base::none) { std::nullopt) {
} }
UserPhotosSlice::UserPhotosSlice( UserPhotosSlice::UserPhotosSlice(
Key key, Key key,
std::deque<PhotoId> &&ids, std::deque<PhotoId> &&ids,
base::optional<int> fullCount, std::optional<int> fullCount,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
base::optional<int> skippedAfter) std::optional<int> skippedAfter)
: _key(key) : _key(key)
, _ids(std::move(ids)) , _ids(std::move(ids))
, _fullCount(fullCount) , _fullCount(fullCount)
@ -74,12 +74,12 @@ void UserPhotosSlice::reverse() {
std::swap(_skippedBefore, _skippedAfter); std::swap(_skippedBefore, _skippedAfter);
} }
base::optional<int> UserPhotosSlice::indexOf(PhotoId photoId) const { std::optional<int> UserPhotosSlice::indexOf(PhotoId photoId) const {
auto it = ranges::find(_ids, photoId); auto it = ranges::find(_ids, photoId);
if (it != _ids.end()) { if (it != _ids.end()) {
return (it - _ids.begin()); return (it - _ids.begin());
} }
return base::none; return std::nullopt;
} }
PhotoId UserPhotosSlice::operator[](int index) const { PhotoId UserPhotosSlice::operator[](int index) const {
@ -88,17 +88,17 @@ PhotoId UserPhotosSlice::operator[](int index) const {
return *(_ids.begin() + index); return *(_ids.begin() + index);
} }
base::optional<int> UserPhotosSlice::distance(const Key &a, const Key &b) const { std::optional<int> UserPhotosSlice::distance(const Key &a, const Key &b) const {
if (a.userId != _key.userId if (a.userId != _key.userId
|| b.userId != _key.userId) { || b.userId != _key.userId) {
return base::none; return std::nullopt;
} }
if (auto i = indexOf(a.photoId)) { if (auto i = indexOf(a.photoId)) {
if (auto j = indexOf(b.photoId)) { if (auto j = indexOf(b.photoId)) {
return *j - *i; return *j - *i;
} }
} }
return base::none; return std::nullopt;
} }
UserPhotosSliceBuilder::UserPhotosSliceBuilder( UserPhotosSliceBuilder::UserPhotosSliceBuilder(
@ -137,9 +137,9 @@ void UserPhotosSliceBuilder::checkInsufficientPhotos() {
} }
void UserPhotosSliceBuilder::mergeSliceData( void UserPhotosSliceBuilder::mergeSliceData(
base::optional<int> count, std::optional<int> count,
const std::deque<PhotoId> &photoIds, const std::deque<PhotoId> &photoIds,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
int skippedAfter) { int skippedAfter) {
if (photoIds.empty()) { if (photoIds.empty()) {
if (_fullCount != count) { if (_fullCount != count) {

View file

@ -18,28 +18,28 @@ public:
UserPhotosSlice( UserPhotosSlice(
Key key, Key key,
std::deque<PhotoId> &&ids, std::deque<PhotoId> &&ids,
base::optional<int> fullCount, std::optional<int> fullCount,
base::optional<int> skippedBefore, std::optional<int> skippedBefore,
base::optional<int> skippedAfter); std::optional<int> skippedAfter);
void reverse(); void reverse();
const Key &key() const { return _key; } const Key &key() const { return _key; }
base::optional<int> fullCount() const { return _fullCount; } std::optional<int> fullCount() const { return _fullCount; }
base::optional<int> skippedBefore() const { return _skippedBefore; } std::optional<int> skippedBefore() const { return _skippedBefore; }
base::optional<int> skippedAfter() const { return _skippedAfter; } std::optional<int> skippedAfter() const { return _skippedAfter; }
base::optional<int> indexOf(PhotoId msgId) const; std::optional<int> indexOf(PhotoId msgId) const;
int size() const { return _ids.size(); } int size() const { return _ids.size(); }
PhotoId operator[](int index) const; PhotoId operator[](int index) const;
base::optional<int> distance(const Key &a, const Key &b) const; std::optional<int> distance(const Key &a, const Key &b) const;
private: private:
Key _key; Key _key;
std::deque<PhotoId> _ids; std::deque<PhotoId> _ids;
base::optional<int> _fullCount; std::optional<int> _fullCount;
base::optional<int> _skippedBefore; std::optional<int> _skippedBefore;
base::optional<int> _skippedAfter; std::optional<int> _skippedAfter;
friend class UserPhotosSliceBuilder; friend class UserPhotosSliceBuilder;

View file

@ -529,8 +529,8 @@ std::pair<QString, QSize> WriteImageThumb(
const QString &basePath, const QString &basePath,
const QString &largePath, const QString &largePath,
Fn<QSize(QSize)> convertSize, Fn<QSize(QSize)> convertSize,
base::optional<QByteArray> format, std::optional<QByteArray> format,
base::optional<int> quality, std::optional<int> quality,
const QString &postfix) { const QString &postfix) {
if (largePath.isEmpty()) { if (largePath.isEmpty()) {
return {}; return {};
@ -582,8 +582,8 @@ QString WriteImageThumb(
basePath, basePath,
largePath, largePath,
[=](QSize size) { return QSize(width, height); }, [=](QSize size) { return QSize(width, height); },
base::none, std::nullopt,
base::none, std::nullopt,
postfix).first; postfix).first;
} }

View file

@ -87,8 +87,8 @@ std::pair<QString, QSize> WriteImageThumb(
const QString &basePath, const QString &basePath,
const QString &largePath, const QString &largePath,
Fn<QSize(QSize)> convertSize, Fn<QSize(QSize)> convertSize,
base::optional<QByteArray> format = base::none, std::optional<QByteArray> format = std::nullopt,
base::optional<int> quality = base::none, std::optional<int> quality = std::nullopt,
const QString &postfix = "_thumb"); const QString &postfix = "_thumb");
QString WriteImageThumb( QString WriteImageThumb(

View file

@ -97,7 +97,7 @@ public:
LoadedFileCache(int limit); LoadedFileCache(int limit);
void save(const Location &location, const QString &relativePath); void save(const Location &location, const QString &relativePath);
base::optional<QString> find(const Location &location) const; std::optional<QString> find(const Location &location) const;
private: private:
int _limit = 0; int _limit = 0;
@ -135,7 +135,7 @@ struct ApiWrap::UserpicsProcess {
FnMut<void()> finish; FnMut<void()> finish;
int processed = 0; int processed = 0;
base::optional<Data::UserpicsSlice> slice; std::optional<Data::UserpicsSlice> slice;
uint64 maxId = 0; uint64 maxId = 0;
bool lastSlice = false; bool lastSlice = false;
int fileIndex = 0; int fileIndex = 0;
@ -207,7 +207,7 @@ struct ApiWrap::ChatProcess {
int32 largestIdPlusOne = 1; int32 largestIdPlusOne = 1;
Data::ParseMediaContext context; Data::ParseMediaContext context;
base::optional<Data::MessagesSlice> slice; std::optional<Data::MessagesSlice> slice;
bool lastSlice = false; bool lastSlice = false;
int fileIndex = 0; int fileIndex = 0;
}; };
@ -309,16 +309,16 @@ void ApiWrap::LoadedFileCache::save(
} }
} }
base::optional<QString> ApiWrap::LoadedFileCache::find( std::optional<QString> ApiWrap::LoadedFileCache::find(
const Location &location) const { const Location &location) const {
if (!location) { if (!location) {
return base::none; return std::nullopt;
} }
const auto key = ComputeLocationKey(location); const auto key = ComputeLocationKey(location);
if (const auto i = _map.find(key); i != end(_map)) { if (const auto i = _map.find(key); i != end(_map)) {
return i->second; return i->second;
} }
return base::none; return std::nullopt;
} }
ApiWrap::FileProcess::FileProcess(const QString &path, Output::Stats *stats) ApiWrap::FileProcess::FileProcess(const QString &path, Output::Stats *stats)
@ -954,7 +954,7 @@ void ApiWrap::requestMessagesCount(int localSplitIndex) {
} }
void ApiWrap::finishExport(FnMut<void()> done) { void ApiWrap::finishExport(FnMut<void()> done) {
const auto guard = gsl::finally([&] { _takeoutId = base::none; }); const auto guard = gsl::finally([&] { _takeoutId = std::nullopt; });
mainRequest(MTPaccount_FinishTakeoutSession( mainRequest(MTPaccount_FinishTakeoutSession(
MTP_flags(MTPaccount_FinishTakeoutSession::Flag::f_success) MTP_flags(MTPaccount_FinishTakeoutSession::Flag::f_success)

View file

@ -191,7 +191,7 @@ private:
void ioError(const Output::Result &result); void ioError(const Output::Result &result);
MTP::ConcurrentSender _mtp; MTP::ConcurrentSender _mtp;
base::optional<uint64> _takeoutId; std::optional<uint64> _takeoutId;
Output::Stats *_stats = nullptr; Output::Stats *_stats = nullptr;
std::unique_ptr<Settings> _settings; std::unique_ptr<Settings> _settings;

View file

@ -32,7 +32,7 @@ bool File::empty() const {
Result File::writeBlock(const QByteArray &block) { Result File::writeBlock(const QByteArray &block) {
const auto result = writeBlockAttempt(block); const auto result = writeBlockAttempt(block);
if (!result) { if (!result) {
_file.clear(); _file.reset();
} }
return result; return result;
} }

View file

@ -46,7 +46,7 @@ private:
QString _path; QString _path;
int _offset = 0; int _offset = 0;
base::optional<QFile> _file; std::optional<QFile> _file;
Stats *_stats = nullptr; Stats *_stats = nullptr;
bool _inStats = false; bool _inStats = false;

View file

@ -1058,7 +1058,7 @@ auto HtmlWriter::Wrap::pushMessage(
} }
return "You have sent the following documents: " return "You have sent the following documents: "
+ SerializeList(list); + SerializeList(list);
}, [](const base::none_type &) { return QByteArray(); }); }, [](std::nullopt_t) { return QByteArray(); });
if (!serviceText.isEmpty()) { if (!serviceText.isEmpty()) {
const auto &content = message.action.content; const auto &content = message.action.content;
@ -1658,7 +1658,7 @@ MediaData HtmlWriter::Wrap::prepareMediaData(
result.status = Data::FormatMoneyAmount(data.amount, data.currency); result.status = Data::FormatMoneyAmount(data.amount, data.currency);
}, [](const UnsupportedMedia &data) { }, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message."); Unexpected("Unsupported message.");
}, [](const base::none_type &) {}); }, [](std::nullopt_t) {});
return result; return result;
} }
@ -2276,7 +2276,7 @@ Result HtmlWriter::writeDialogSlice(const Data::MessagesSlice &data) {
? ((_messagesCount - 1) / kMessagesInFile) ? ((_messagesCount - 1) / kMessagesInFile)
: 0; : 0;
auto previous = _lastMessageInfo.get(); auto previous = _lastMessageInfo.get();
auto saved = base::optional<MessageInfo>(); auto saved = std::optional<MessageInfo>();
auto block = QByteArray(); auto block = QByteArray();
for (const auto &message : data.list) { for (const auto &message : data.list) {
const auto newIndex = (_messagesCount / kMessagesInFile); const auto newIndex = (_messagesCount / kMessagesInFile);
@ -2291,7 +2291,7 @@ Result HtmlWriter::writeDialogSlice(const Data::MessagesSlice &data) {
block = QByteArray(); block = QByteArray();
_lastMessageInfo = nullptr; _lastMessageInfo = nullptr;
previous = nullptr; previous = nullptr;
saved = base::none; saved = std::nullopt;
oldIndex = newIndex; oldIndex = newIndex;
} else { } else {
return next; return next;

View file

@ -458,7 +458,7 @@ QByteArray SerializeMessage(
}())); }()));
} }
pushBare("values", SerializeArray(context, list)); pushBare("values", SerializeArray(context, list));
}, [](const base::none_type &) {}); }, [](std::nullopt_t) {});
if (!message.action.content) { if (!message.action.content) {
pushFrom(); pushFrom();
@ -572,7 +572,7 @@ QByteArray SerializeMessage(
})); }));
}, [](const UnsupportedMedia &data) { }, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message."); Unexpected("Unsupported message.");
}, [](const base::none_type &) {}); }, [](std::nullopt_t) {});
pushBare("text", SerializeText(context, message.text)); pushBare("text", SerializeText(context, message.text));

View file

@ -332,7 +332,7 @@ QByteArray SerializeMessage(
} else if (!list.empty()) { } else if (!list.empty()) {
push("Values", JoinList(", ", list)); push("Values", JoinList(", ", list));
} }
}, [](const base::none_type &) {}); }, [](std::nullopt_t) {});
if (!message.action.content) { if (!message.action.content) {
pushFrom(); pushFrom();
@ -435,7 +435,7 @@ QByteArray SerializeMessage(
})); }));
}, [](const UnsupportedMedia &data) { }, [](const UnsupportedMedia &data) {
Unexpected("Unsupported message."); Unexpected("Unsupported message.");
}, [](const base::none_type &) {}); }, [](std::nullopt_t) {});
auto value = JoinList(QByteArray(), ranges::view::all( auto value = JoinList(QByteArray(), ranges::view::all(
message.text message.text

View file

@ -199,7 +199,7 @@ void Widget::updateScrollDownVisibility() {
return; return;
} }
const auto scrollDownIsVisible = [&]() -> base::optional<bool> { const auto scrollDownIsVisible = [&]() -> std::optional<bool> {
const auto top = _scroll->scrollTop() + st::historyToDownShownAfter; const auto top = _scroll->scrollTop() + st::historyToDownShownAfter;
if (top < _scroll->scrollTopMax()) { if (top < _scroll->scrollTopMax()) {
return true; return true;
@ -207,7 +207,7 @@ void Widget::updateScrollDownVisibility() {
if (_inner->loadedAtBottomKnown()) { if (_inner->loadedAtBottomKnown()) {
return !_inner->loadedAtBottom(); return !_inner->loadedAtBottom();
} }
return base::none; return std::nullopt;
}; };
const auto scrollDownIsShown = scrollDownIsVisible(); const auto scrollDownIsShown = scrollDownIsVisible();
if (!scrollDownIsShown) { if (!scrollDownIsShown) {
@ -368,11 +368,11 @@ void Widget::listVisibleItemsChanged(HistoryItemsList &&items) {
} }
} }
base::optional<int> Widget::listUnreadBarView( std::optional<int> Widget::listUnreadBarView(
const std::vector<not_null<Element*>> &elements) { const std::vector<not_null<Element*>> &elements) {
const auto position = _feed->unreadPosition(); const auto position = _feed->unreadPosition();
if (!position || elements.empty() || !_feed->unreadCount()) { if (!position || elements.empty() || !_feed->unreadCount()) {
return base::none; return std::nullopt;
} }
const auto minimal = ranges::upper_bound( const auto minimal = ranges::upper_bound(
elements, elements,
@ -380,14 +380,14 @@ base::optional<int> Widget::listUnreadBarView(
std::less<>(), std::less<>(),
[](auto view) { return view->data()->position(); }); [](auto view) { return view->data()->position(); });
if (minimal == end(elements)) { if (minimal == end(elements)) {
return base::none; return std::nullopt;
} }
const auto view = *minimal; const auto view = *minimal;
const auto unreadMessagesHeight = elements.back()->y() const auto unreadMessagesHeight = elements.back()->y()
+ elements.back()->height() + elements.back()->height()
- view->y(); - view->y();
if (unreadMessagesHeight < _scroll->height()) { if (unreadMessagesHeight < _scroll->height()) {
return base::none; return std::nullopt;
} }
return base::make_optional(int(minimal - begin(elements))); return base::make_optional(int(minimal - begin(elements)));
} }
@ -482,7 +482,7 @@ void Widget::updateControlsGeometry() {
const auto contentWidth = width(); const auto contentWidth = width();
const auto newScrollTop = _scroll->isHidden() const auto newScrollTop = _scroll->isHidden()
? base::none ? std::nullopt
: base::make_optional(_scroll->scrollTop() + topDelta()); : base::make_optional(_scroll->scrollTop() + topDelta());
_topBar->resizeToWidth(contentWidth); _topBar->resizeToWidth(contentWidth);
_topBarShadow->resize(contentWidth, st::lineWidth); _topBarShadow->resize(contentWidth, st::lineWidth);

View file

@ -86,7 +86,7 @@ public:
void listSelectionChanged( void listSelectionChanged(
HistoryView::SelectedItems &&items) override; HistoryView::SelectedItems &&items) override;
void listVisibleItemsChanged(HistoryItemsList &&items) override; void listVisibleItemsChanged(HistoryItemsList &&items) override;
base::optional<int> listUnreadBarView( std::optional<int> listUnreadBarView(
const std::vector<not_null<Element*>> &elements) override; const std::vector<not_null<Element*>> &elements) override;
void listContentRefreshed() override; void listContentRefreshed() override;
ClickHandlerPtr listDateLink(not_null<Element*> view) override; ClickHandlerPtr listDateLink(not_null<Element*> view) override;
@ -135,7 +135,7 @@ private:
FullMsgId _currentMessageId; FullMsgId _currentMessageId;
FullMsgId _highlightMessageId; FullMsgId _highlightMessageId;
base::optional<Data::MessagePosition> _nextAnimatedScrollPosition; std::optional<Data::MessagePosition> _nextAnimatedScrollPosition;
int _nextAnimatedScrollDelta = 0; int _nextAnimatedScrollDelta = 0;
Animation _scrollDownShown; Animation _scrollDownShown;

View file

@ -294,7 +294,7 @@ void History::setHasPendingResizedItems() {
void History::itemRemoved(not_null<HistoryItem*> item) { void History::itemRemoved(not_null<HistoryItem*> item) {
item->removeMainView(); item->removeMainView();
if (lastMessage() == item) { if (lastMessage() == item) {
_lastMessage = base::none; _lastMessage = std::nullopt;
if (loadedAtBottom()) { if (loadedAtBottom()) {
if (const auto last = lastAvailableMessage()) { if (const auto last = lastAvailableMessage()) {
setLastMessage(last); setLastMessage(last);
@ -423,7 +423,7 @@ void History::setSentDraftText(const QString &text) {
void History::clearSentDraftText(const QString &text) { void History::clearSentDraftText(const QString &text) {
if (_lastSentDraftText && *_lastSentDraftText == text) { if (_lastSentDraftText && *_lastSentDraftText == text) {
_lastSentDraftText = base::none; _lastSentDraftText = std::nullopt;
} }
accumulate_max(_lastSentDraftTime, unixtime()); accumulate_max(_lastSentDraftTime, unixtime());
} }

View file

@ -491,12 +491,12 @@ private:
bool _loadedAtTop = false; bool _loadedAtTop = false;
bool _loadedAtBottom = true; bool _loadedAtBottom = true;
base::optional<MsgId> _inboxReadBefore; std::optional<MsgId> _inboxReadBefore;
base::optional<MsgId> _outboxReadBefore; std::optional<MsgId> _outboxReadBefore;
base::optional<int> _unreadCount; std::optional<int> _unreadCount;
base::optional<int> _unreadMentionsCount; std::optional<int> _unreadMentionsCount;
base::flat_set<MsgId> _unreadMentions; base::flat_set<MsgId> _unreadMentions;
base::optional<HistoryItem*> _lastMessage; std::optional<HistoryItem*> _lastMessage;
bool _unreadMark = false; bool _unreadMark = false;
// A pointer to the block that is currently being built. // A pointer to the block that is currently being built.
@ -510,7 +510,7 @@ private:
std::unique_ptr<Data::Draft> _localDraft, _cloudDraft; std::unique_ptr<Data::Draft> _localDraft, _cloudDraft;
std::unique_ptr<Data::Draft> _editDraft; std::unique_ptr<Data::Draft> _editDraft;
base::optional<QString> _lastSentDraftText; std::optional<QString> _lastSentDraftText;
TimeId _lastSentDraftTime = 0; TimeId _lastSentDraftTime = 0;
MessageIdsList _forwardDraft; MessageIdsList _forwardDraft;

View file

@ -4584,7 +4584,7 @@ void HistoryWidget::documentUploaded(
const FullMsgId &newId, const FullMsgId &newId,
bool silent, bool silent,
const MTPInputFile &file) { const MTPInputFile &file) {
Auth().api().sendUploadedDocument(newId, file, base::none, silent); Auth().api().sendUploadedDocument(newId, file, std::nullopt, silent);
} }
void HistoryWidget::thumbDocumentUploaded( void HistoryWidget::thumbDocumentUploaded(
@ -5071,7 +5071,7 @@ bool HistoryWidget::hasPendingResizedItems() const {
|| (_migrated && _migrated->hasPendingResizedItems()); || (_migrated && _migrated->hasPendingResizedItems());
} }
base::optional<int> HistoryWidget::unreadBarTop() const { std::optional<int> HistoryWidget::unreadBarTop() const {
auto getUnreadBar = [this]() -> HistoryView::Element* { auto getUnreadBar = [this]() -> HistoryView::Element* {
if (const auto bar = _migrated ? _migrated->unreadBar() : nullptr) { if (const auto bar = _migrated ? _migrated->unreadBar() : nullptr) {
return bar; return bar;
@ -5088,7 +5088,7 @@ base::optional<int> HistoryWidget::unreadBarTop() const {
} }
return result; return result;
} }
return base::none; return std::nullopt;
} }
HistoryView::Element *HistoryWidget::firstUnreadMessage() const { HistoryView::Element *HistoryWidget::firstUnreadMessage() const {

View file

@ -684,7 +684,7 @@ private:
// Counts scrollTop for placing the scroll right at the unread // Counts scrollTop for placing the scroll right at the unread
// messages bar, choosing from _history and _migrated unreadBar. // messages bar, choosing from _history and _migrated unreadBar.
base::optional<int> unreadBarTop() const; std::optional<int> unreadBarTop() const;
int itemTopForHighlight(not_null<HistoryView::Element*> view) const; int itemTopForHighlight(not_null<HistoryView::Element*> view) const;
void scrollToCurrentVoiceMessage(FullMsgId fromId, FullMsgId toId); void scrollToCurrentVoiceMessage(FullMsgId fromId, FullMsgId toId);
HistoryView::Element *firstUnreadMessage() const; HistoryView::Element *firstUnreadMessage() const;

View file

@ -328,24 +328,24 @@ void ListWidget::refreshRows() {
_delegate->listContentRefreshed(); _delegate->listContentRefreshed();
} }
base::optional<int> ListWidget::scrollTopForPosition( std::optional<int> ListWidget::scrollTopForPosition(
Data::MessagePosition position) const { Data::MessagePosition position) const {
if (position == Data::MaxMessagePosition) { if (position == Data::MaxMessagePosition) {
if (loadedAtBottom()) { if (loadedAtBottom()) {
return height(); return height();
} }
return base::none; return std::nullopt;
} else if (_items.empty() } else if (_items.empty()
|| isBelowPosition(position) || isBelowPosition(position)
|| isAbovePosition(position)) { || isAbovePosition(position)) {
return base::none; return std::nullopt;
} }
const auto index = findNearestItem(position); const auto index = findNearestItem(position);
const auto view = _items[index]; const auto view = _items[index];
return scrollTopForView(_items[index]); return scrollTopForView(_items[index]);
} }
base::optional<int> ListWidget::scrollTopForView( std::optional<int> ListWidget::scrollTopForView(
not_null<Element*> view) const { not_null<Element*> view) const {
if (view->isHiddenByGroup()) { if (view->isHiddenByGroup()) {
if (const auto group = Auth().data().groups().find(view->data())) { if (const auto group = Auth().data().groups().find(view->data())) {

View file

@ -62,7 +62,7 @@ public:
not_null<HistoryItem*> second) = 0; not_null<HistoryItem*> second) = 0;
virtual void listSelectionChanged(SelectedItems &&items) = 0; virtual void listSelectionChanged(SelectedItems &&items) = 0;
virtual void listVisibleItemsChanged(HistoryItemsList &&items) = 0; virtual void listVisibleItemsChanged(HistoryItemsList &&items) = 0;
virtual base::optional<int> listUnreadBarView( virtual std::optional<int> listUnreadBarView(
const std::vector<not_null<Element*>> &elements) = 0; const std::vector<not_null<Element*>> &elements) = 0;
virtual void listContentRefreshed() = 0; virtual void listContentRefreshed() = 0;
virtual ClickHandlerPtr listDateLink(not_null<Element*> view) = 0; virtual ClickHandlerPtr listDateLink(not_null<Element*> view) = 0;
@ -136,9 +136,9 @@ public:
void saveState(not_null<ListMemento*> memento); void saveState(not_null<ListMemento*> memento);
void restoreState(not_null<ListMemento*> memento); void restoreState(not_null<ListMemento*> memento);
base::optional<int> scrollTopForPosition( std::optional<int> scrollTopForPosition(
Data::MessagePosition position) const; Data::MessagePosition position) const;
base::optional<int> scrollTopForView(not_null<Element*> view) const; std::optional<int> scrollTopForView(not_null<Element*> view) const;
enum class AnimatedScroll { enum class AnimatedScroll {
Full, Full,
Part, Part,

View file

@ -33,7 +33,7 @@ namespace FeedProfile {
class Memento; class Memento;
struct ChannelsState { struct ChannelsState {
std::unique_ptr<PeerListState> list; std::unique_ptr<PeerListState> list;
base::optional<QString> search; std::optional<QString> search;
}; };
class Channels class Channels

View file

@ -981,7 +981,7 @@ auto ListWidget::findItemByPoint(QPoint point) const -> FoundItem {
} }
auto ListWidget::findItemById( auto ListWidget::findItemById(
UniversalMsgId universalId) -> base::optional<FoundItem> { UniversalMsgId universalId) -> std::optional<FoundItem> {
auto sectionIt = findSectionByItem(universalId); auto sectionIt = findSectionByItem(universalId);
if (sectionIt != _sections.end()) { if (sectionIt != _sections.end()) {
auto item = sectionIt->findItemNearId(universalId); auto item = sectionIt->findItemNearId(universalId);
@ -989,14 +989,14 @@ auto ListWidget::findItemById(
return foundItemInSection(item, *sectionIt); return foundItemInSection(item, *sectionIt);
} }
} }
return base::none; return std::nullopt;
} }
auto ListWidget::findItemDetails( auto ListWidget::findItemDetails(
BaseLayout *item) -> base::optional<FoundItem> { BaseLayout *item) -> std::optional<FoundItem> {
return item return item
? findItemById(GetUniversalId(item)) ? findItemById(GetUniversalId(item))
: base::none; : std::nullopt;
} }
auto ListWidget::foundItemInSection( auto ListWidget::foundItemInSection(
@ -1058,7 +1058,7 @@ void ListWidget::checkMoveToOtherViewer() {
auto delta = _slice.distance( auto delta = _slice.distance(
sliceKey(_universalAroundId), sliceKey(_universalAroundId),
sliceKey(universalId)); sliceKey(universalId));
Assert(delta != base::none); Assert(delta != std::nullopt);
preloadRequired = (qAbs(*delta) >= minUniversalIdDelta); preloadRequired = (qAbs(*delta) >= minUniversalIdDelta);
} }
if (preloadRequired) { if (preloadRequired) {

View file

@ -230,8 +230,8 @@ private:
std::vector<Section>::const_iterator from, std::vector<Section>::const_iterator from,
int bottom) const; int bottom) const;
FoundItem findItemByPoint(QPoint point) const; FoundItem findItemByPoint(QPoint point) const;
base::optional<FoundItem> findItemById(UniversalMsgId universalId); std::optional<FoundItem> findItemById(UniversalMsgId universalId);
base::optional<FoundItem> findItemDetails(BaseLayout *item); std::optional<FoundItem> findItemDetails(BaseLayout *item);
FoundItem foundItemInSection( FoundItem foundItemInSection(
const FoundItem &item, const FoundItem &item,
const Section &section) const; const Section &section) const;

View file

@ -16,13 +16,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info { namespace Info {
namespace Media { namespace Media {
base::optional<int> TypeToTabIndex(Type type) { std::optional<int> TypeToTabIndex(Type type) {
switch (type) { switch (type) {
case Type::Photo: return 0; case Type::Photo: return 0;
case Type::Video: return 1; case Type::Video: return 1;
case Type::File: return 2; case Type::File: return 2;
} }
return base::none; return std::nullopt;
} }
Type TabIndexToType(int index) { Type TabIndexToType(int index) {

View file

@ -17,7 +17,7 @@ namespace Media {
using Type = Storage::SharedMediaType; using Type = Storage::SharedMediaType;
base::optional<int> TypeToTabIndex(Type type); std::optional<int> TypeToTabIndex(Type type);
Type TabIndexToType(int index); Type TabIndexToType(int index);
class InnerWidget; class InnerWidget;

View file

@ -62,7 +62,7 @@ bool Button::toggled() const {
return _toggle ? _toggle->checked() : false; return _toggle ? _toggle->checked() : false;
} }
void Button::setColorOverride(base::optional<QColor> textColorOverride) { void Button::setColorOverride(std::optional<QColor> textColorOverride) {
_textColorOverride = textColorOverride; _textColorOverride = textColorOverride;
update(); update();
} }

View file

@ -30,7 +30,7 @@ public:
rpl::producer<bool> toggledValue() const; rpl::producer<bool> toggledValue() const;
bool toggled() const; bool toggled() const;
void setColorOverride(base::optional<QColor> textColorOverride); void setColorOverride(std::optional<QColor> textColorOverride);
protected: protected:
int resizeGetHeight(int newWidth) override; int resizeGetHeight(int newWidth) override;
@ -51,7 +51,7 @@ private:
int _originalWidth = 0; int _originalWidth = 0;
int _textWidth = 0; int _textWidth = 0;
std::unique_ptr<Ui::ToggleView> _toggle; std::unique_ptr<Ui::ToggleView> _toggle;
base::optional<QColor> _textColorOverride; std::optional<QColor> _textColorOverride;
}; };

View file

@ -34,7 +34,7 @@ class Button;
class Memento; class Memento;
struct MembersState { struct MembersState {
std::unique_ptr<PeerListState> list; std::unique_ptr<PeerListState> list;
base::optional<QString> search; std::optional<QString> search;
}; };
class Members class Members

View file

@ -127,7 +127,7 @@ void Instance::playlistUpdated(not_null<Data*> data) {
const auto fullId = data->current.contextId(); const auto fullId = data->current.contextId();
data->playlistIndex = data->playlistSlice->indexOf(fullId); data->playlistIndex = data->playlistSlice->indexOf(fullId);
} else { } else {
data->playlistIndex = base::none; data->playlistIndex = std::nullopt;
} }
data->playlistChanges.fire({}); data->playlistChanges.fire({});
} }
@ -146,7 +146,7 @@ bool Instance::validPlaylist(not_null<Data*> data) {
return [&](const SparseIdsMergedSlice &data) { return [&](const SparseIdsMergedSlice &data) {
return inSameDomain(a, b) return inSameDomain(a, b)
? data.distance(a, b) ? data.distance(a, b)
: base::optional<int>(); : std::optional<int>();
}; };
}; };
@ -180,14 +180,14 @@ void Instance::validatePlaylist(not_null<Data*> data) {
playlistUpdated(data); playlistUpdated(data);
}, data->playlistLifetime); }, data->playlistLifetime);
} else { } else {
data->playlistSlice = base::none; data->playlistSlice = std::nullopt;
data->playlistSliceKey = data->playlistRequestedKey = base::none; data->playlistSliceKey = data->playlistRequestedKey = std::nullopt;
playlistUpdated(data); playlistUpdated(data);
} }
} }
auto Instance::playlistKey(not_null<Data*> data) const auto Instance::playlistKey(not_null<Data*> data) const
-> base::optional<SliceKey> { -> std::optional<SliceKey> {
const auto contextId = data->current.contextId(); const auto contextId = data->current.contextId();
const auto history = data->history; const auto history = data->history;
if (!contextId || !history || !IsServerMsgId(contextId.msg)) { if (!contextId || !history || !IsServerMsgId(contextId.msg)) {

View file

@ -139,10 +139,10 @@ private:
Storage::SharedMediaType overview; Storage::SharedMediaType overview;
AudioMsgId current; AudioMsgId current;
AudioMsgId seeking; AudioMsgId seeking;
base::optional<SparseIdsMergedSlice> playlistSlice; std::optional<SparseIdsMergedSlice> playlistSlice;
base::optional<SliceKey> playlistSliceKey; std::optional<SliceKey> playlistSliceKey;
base::optional<SliceKey> playlistRequestedKey; std::optional<SliceKey> playlistRequestedKey;
base::optional<int> playlistIndex; std::optional<int> playlistIndex;
rpl::lifetime playlistLifetime; rpl::lifetime playlistLifetime;
rpl::event_stream<> playlistChanges; rpl::event_stream<> playlistChanges;
History *history = nullptr; History *history = nullptr;
@ -156,7 +156,7 @@ private:
void setCurrent(const AudioMsgId &audioId); void setCurrent(const AudioMsgId &audioId);
void refreshPlaylist(not_null<Data*> data); void refreshPlaylist(not_null<Data*> data);
base::optional<SliceKey> playlistKey(not_null<Data*> data) const; std::optional<SliceKey> playlistKey(not_null<Data*> data) const;
bool validPlaylist(not_null<Data*> data); bool validPlaylist(not_null<Data*> data);
void validatePlaylist(not_null<Data*> data); void validatePlaylist(not_null<Data*> data);
void playlistUpdated(not_null<Data*> data); void playlistUpdated(not_null<Data*> data);

View file

@ -53,7 +53,7 @@ Context ComputeContext(const SharedMediaWithLastSlice &slice, int index) {
if (const auto peer = (*photo)->peer) { if (const auto peer = (*photo)->peer) {
return peer->id; return peer->id;
} }
return base::none; return std::nullopt;
} else if (const auto msgId = base::get_if<FullMsgId>(&value)) { } else if (const auto msgId = base::get_if<FullMsgId>(&value)) {
if (const auto item = App::histItemById(*msgId)) { if (const auto item = App::histItemById(*msgId)) {
if (!item->toHistoryMessage()) { if (!item->toHistoryMessage()) {
@ -62,7 +62,7 @@ Context ComputeContext(const SharedMediaWithLastSlice &slice, int index) {
return groupId; return groupId;
} }
} }
return base::none; return std::nullopt;
} }
Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)"); Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)");
} }

View file

@ -464,7 +464,7 @@ void MediaView::updateActions() {
} }
auto MediaView::computeOverviewType() const auto MediaView::computeOverviewType() const
-> base::optional<SharedMediaType> { -> std::optional<SharedMediaType> {
if (const auto mediaType = sharedMediaType()) { if (const auto mediaType = sharedMediaType()) {
if (const auto overviewType = SharedMediaOverviewType(*mediaType)) { if (const auto overviewType = SharedMediaOverviewType(*mediaType)) {
return overviewType; return overviewType;
@ -476,7 +476,7 @@ auto MediaView::computeOverviewType() const
} }
} }
} }
return base::none; return std::nullopt;
} }
void MediaView::step_state(TimeMs ms, bool timer) { void MediaView::step_state(TimeMs ms, bool timer) {
@ -697,7 +697,7 @@ void MediaView::clearData() {
stopGif(); stopGif();
delete _menu; delete _menu;
_menu = nullptr; _menu = nullptr;
setContext(base::none); setContext(std::nullopt);
_from = nullptr; _from = nullptr;
_photo = nullptr; _photo = nullptr;
_doc = nullptr; _doc = nullptr;
@ -1082,7 +1082,7 @@ void MediaView::onCopy() {
} }
} }
base::optional<MediaView::SharedMediaType> MediaView::sharedMediaType() const { std::optional<MediaView::SharedMediaType> MediaView::sharedMediaType() const {
using Type = SharedMediaType; using Type = SharedMediaType;
if (auto item = App::histItemById(_msgid)) { if (auto item = App::histItemById(_msgid)) {
if (_photo) { if (_photo) {
@ -1099,10 +1099,10 @@ base::optional<MediaView::SharedMediaType> MediaView::sharedMediaType() const {
return Type::File; return Type::File;
} }
} }
return base::none; return std::nullopt;
} }
base::optional<MediaView::SharedMediaKey> MediaView::sharedMediaKey() const { std::optional<MediaView::SharedMediaKey> MediaView::sharedMediaKey() const {
if (!_msgid && _peer && !_user && _photo && _peer->userpicPhotoId() == _photo->id) { if (!_msgid && _peer && !_user && _photo && _peer->userpicPhotoId() == _photo->id) {
return SharedMediaKey { return SharedMediaKey {
_history->peer->id, _history->peer->id,
@ -1112,7 +1112,7 @@ base::optional<MediaView::SharedMediaKey> MediaView::sharedMediaKey() const {
}; };
} }
if (!IsServerMsgId(_msgid.msg)) { if (!IsServerMsgId(_msgid.msg)) {
return base::none; return std::nullopt;
} }
auto keyForType = [this](SharedMediaType type) -> SharedMediaKey { auto keyForType = [this](SharedMediaType type) -> SharedMediaKey {
return { return {
@ -1152,7 +1152,7 @@ bool MediaView::validSharedMedia() const {
return [&](const SharedMediaWithLastSlice &data) { return [&](const SharedMediaWithLastSlice &data) {
return inSameDomain(a, b) return inSameDomain(a, b)
? data.distance(a, b) ? data.distance(a, b)
: base::optional<int>(); : std::optional<int>();
}; };
}; };
@ -1188,15 +1188,15 @@ void MediaView::validateSharedMedia() {
}, _sharedMedia->lifetime); }, _sharedMedia->lifetime);
} else { } else {
_sharedMedia = nullptr; _sharedMedia = nullptr;
_sharedMediaData = base::none; _sharedMediaData = std::nullopt;
_sharedMediaDataKey = base::none; _sharedMediaDataKey = std::nullopt;
} }
} }
void MediaView::handleSharedMediaUpdate(SharedMediaWithLastSlice &&update) { void MediaView::handleSharedMediaUpdate(SharedMediaWithLastSlice &&update) {
if ((!_photo && !_doc) || !_sharedMedia) { if ((!_photo && !_doc) || !_sharedMedia) {
_sharedMediaData = base::none; _sharedMediaData = std::nullopt;
_sharedMediaDataKey = base::none; _sharedMediaDataKey = std::nullopt;
} else { } else {
_sharedMediaData = std::move(update); _sharedMediaData = std::move(update);
_sharedMediaDataKey = _sharedMedia->key; _sharedMediaDataKey = _sharedMedia->key;
@ -1206,14 +1206,14 @@ void MediaView::handleSharedMediaUpdate(SharedMediaWithLastSlice &&update) {
preloadData(0); preloadData(0);
} }
base::optional<MediaView::UserPhotosKey> MediaView::userPhotosKey() const { std::optional<MediaView::UserPhotosKey> MediaView::userPhotosKey() const {
if (!_msgid && _user && _photo) { if (!_msgid && _user && _photo) {
return UserPhotosKey { return UserPhotosKey {
_user->bareId(), _user->bareId(),
_photo->id _photo->id
}; };
} }
return base::none; return std::nullopt;
} }
bool MediaView::validUserPhotos() const { bool MediaView::validUserPhotos() const {
@ -1251,13 +1251,13 @@ void MediaView::validateUserPhotos() {
}, _userPhotos->lifetime); }, _userPhotos->lifetime);
} else { } else {
_userPhotos = nullptr; _userPhotos = nullptr;
_userPhotosData = base::none; _userPhotosData = std::nullopt;
} }
} }
void MediaView::handleUserPhotosUpdate(UserPhotosSlice &&update) { void MediaView::handleUserPhotosUpdate(UserPhotosSlice &&update) {
if (!_photo || !_userPhotos) { if (!_photo || !_userPhotos) {
_userPhotosData = base::none; _userPhotosData = std::nullopt;
} else { } else {
_userPhotosData = std::move(update); _userPhotosData = std::move(update);
} }
@ -1358,7 +1358,7 @@ void MediaView::showPhoto(not_null<PhotoData*> photo, HistoryItem *context) {
if (context) { if (context) {
setContext(context); setContext(context);
} else { } else {
setContext(base::none); setContext(std::nullopt);
} }
_firstOpenedPeerPhoto = false; _firstOpenedPeerPhoto = false;
@ -1410,7 +1410,7 @@ void MediaView::showDocument(not_null<DocumentData*> document, HistoryItem *cont
if (context) { if (context) {
setContext(context); setContext(context);
} else { } else {
setContext(base::none); setContext(std::nullopt);
} }
_photo = nullptr; _photo = nullptr;
@ -2467,19 +2467,19 @@ MediaView::Entity MediaView::entityForUserPhotos(int index) const {
Expects(!!_userPhotosData); Expects(!!_userPhotosData);
if (index < 0 || index >= _userPhotosData->size()) { if (index < 0 || index >= _userPhotosData->size()) {
return { base::none, nullptr }; return { std::nullopt, nullptr };
} }
if (auto photo = Auth().data().photo((*_userPhotosData)[index])) { if (auto photo = Auth().data().photo((*_userPhotosData)[index])) {
return { photo, nullptr }; return { photo, nullptr };
} }
return { base::none, nullptr }; return { std::nullopt, nullptr };
} }
MediaView::Entity MediaView::entityForSharedMedia(int index) const { MediaView::Entity MediaView::entityForSharedMedia(int index) const {
Expects(!!_sharedMediaData); Expects(!!_sharedMediaData);
if (index < 0 || index >= _sharedMediaData->size()) { if (index < 0 || index >= _sharedMediaData->size()) {
return { base::none, nullptr }; return { std::nullopt, nullptr };
} }
auto value = (*_sharedMediaData)[index]; auto value = (*_sharedMediaData)[index];
if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) { if (const auto photo = base::get_if<not_null<PhotoData*>>(&value)) {
@ -2488,7 +2488,7 @@ MediaView::Entity MediaView::entityForSharedMedia(int index) const {
} else if (const auto itemId = base::get_if<FullMsgId>(&value)) { } else if (const auto itemId = base::get_if<FullMsgId>(&value)) {
return entityForItemId(*itemId); return entityForItemId(*itemId);
} }
return { base::none, nullptr }; return { std::nullopt, nullptr };
} }
MediaView::Entity MediaView::entityForItemId(const FullMsgId &itemId) const { MediaView::Entity MediaView::entityForItemId(const FullMsgId &itemId) const {
@ -2500,9 +2500,9 @@ MediaView::Entity MediaView::entityForItemId(const FullMsgId &itemId) const {
return { document, item }; return { document, item };
} }
} }
return { base::none, item }; return { std::nullopt, item };
} }
return { base::none, nullptr }; return { std::nullopt, nullptr };
} }
MediaView::Entity MediaView::entityByIndex(int index) const { MediaView::Entity MediaView::entityByIndex(int index) const {
@ -2511,7 +2511,7 @@ MediaView::Entity MediaView::entityByIndex(int index) const {
} else if (_userPhotosData) { } else if (_userPhotosData) {
return entityForUserPhotos(index); return entityForUserPhotos(index);
} }
return { base::none, nullptr }; return { std::nullopt, nullptr };
} }
void MediaView::setContext(base::optional_variant< void MediaView::setContext(base::optional_variant<
@ -2563,7 +2563,7 @@ bool MediaView::moveToEntity(const Entity &entity, int preloadDelta) {
} else if (_peer) { } else if (_peer) {
setContext(_peer); setContext(_peer);
} else { } else {
setContext(base::none); setContext(std::nullopt);
} }
stopGif(); stopGif();
if (auto photo = base::get_if<not_null<PhotoData*>>(&entity.data)) { if (auto photo = base::get_if<not_null<PhotoData*>>(&entity.data)) {
@ -3004,10 +3004,10 @@ bool MediaView::eventFilter(QObject *obj, QEvent *e) {
void MediaView::setVisible(bool visible) { void MediaView::setVisible(bool visible) {
if (!visible) { if (!visible) {
_sharedMedia = nullptr; _sharedMedia = nullptr;
_sharedMediaData = base::none; _sharedMediaData = std::nullopt;
_sharedMediaDataKey = base::none; _sharedMediaDataKey = std::nullopt;
_userPhotos = nullptr; _userPhotos = nullptr;
_userPhotosData = base::none; _userPhotosData = std::nullopt;
if (_menu) _menu->hideMenu(true); if (_menu) _menu->hideMenu(true);
_controlsHideTimer.stop(); _controlsHideTimer.stop();
_controlsState = ControlsShown; _controlsState = ControlsShown;
@ -3064,19 +3064,19 @@ void MediaView::findCurrent() {
if (_sharedMediaData) { if (_sharedMediaData) {
_index = _msgid _index = _msgid
? _sharedMediaData->indexOf(_msgid) ? _sharedMediaData->indexOf(_msgid)
: _photo ? _sharedMediaData->indexOf(_photo) : base::none; : _photo ? _sharedMediaData->indexOf(_photo) : std::nullopt;
_fullIndex = _sharedMediaData->skippedBefore() _fullIndex = _sharedMediaData->skippedBefore()
? (_index | func::add(*_sharedMediaData->skippedBefore())) ? (_index | func::add(*_sharedMediaData->skippedBefore()))
: base::none; : std::nullopt;
_fullCount = _sharedMediaData->fullCount(); _fullCount = _sharedMediaData->fullCount();
} else if (_userPhotosData) { } else if (_userPhotosData) {
_index = _photo ? _userPhotosData->indexOf(_photo->id) : base::none; _index = _photo ? _userPhotosData->indexOf(_photo->id) : std::nullopt;
_fullIndex = _userPhotosData->skippedBefore() _fullIndex = _userPhotosData->skippedBefore()
? (_index | func::add(*_userPhotosData->skippedBefore())) ? (_index | func::add(*_userPhotosData->skippedBefore()))
: base::none; : std::nullopt;
_fullCount = _userPhotosData->fullCount(); _fullCount = _userPhotosData->fullCount();
} else { } else {
_index = _fullIndex = _fullCount = base::none; _index = _fullIndex = _fullCount = std::nullopt;
} }
} }
@ -3105,7 +3105,7 @@ void MediaView::updateHeader() {
_headerText = lang(lng_mediaview_single_photo); _headerText = lang(lng_mediaview_single_photo);
} }
} }
_headerHasLink = computeOverviewType() != base::none; _headerHasLink = computeOverviewType() != std::nullopt;
auto hwidth = st::mediaviewThickFont->width(_headerText); auto hwidth = st::mediaviewThickFont->width(_headerText);
if (hwidth > width() / 3) { if (hwidth > width() / 3) {
hwidth = width() / 3; hwidth = width() / 3;

View file

@ -161,16 +161,16 @@ private:
struct SharedMedia; struct SharedMedia;
using SharedMediaType = SharedMediaWithLastSlice::Type; using SharedMediaType = SharedMediaWithLastSlice::Type;
using SharedMediaKey = SharedMediaWithLastSlice::Key; using SharedMediaKey = SharedMediaWithLastSlice::Key;
base::optional<SharedMediaType> sharedMediaType() const; std::optional<SharedMediaType> sharedMediaType() const;
base::optional<SharedMediaKey> sharedMediaKey() const; std::optional<SharedMediaKey> sharedMediaKey() const;
base::optional<SharedMediaType> computeOverviewType() const; std::optional<SharedMediaType> computeOverviewType() const;
bool validSharedMedia() const; bool validSharedMedia() const;
void validateSharedMedia(); void validateSharedMedia();
void handleSharedMediaUpdate(SharedMediaWithLastSlice &&update); void handleSharedMediaUpdate(SharedMediaWithLastSlice &&update);
struct UserPhotos; struct UserPhotos;
using UserPhotosKey = UserPhotosSlice::Key; using UserPhotosKey = UserPhotosSlice::Key;
base::optional<UserPhotosKey> userPhotosKey() const; std::optional<UserPhotosKey> userPhotosKey() const;
bool validUserPhotos() const; bool validUserPhotos() const;
void validateUserPhotos(); void validateUserPhotos();
void handleUserPhotosUpdate(UserPhotosSlice &&update); void handleUserPhotosUpdate(UserPhotosSlice &&update);
@ -249,10 +249,10 @@ private:
PhotoData *_photo = nullptr; PhotoData *_photo = nullptr;
DocumentData *_doc = nullptr; DocumentData *_doc = nullptr;
std::unique_ptr<SharedMedia> _sharedMedia; std::unique_ptr<SharedMedia> _sharedMedia;
base::optional<SharedMediaWithLastSlice> _sharedMediaData; std::optional<SharedMediaWithLastSlice> _sharedMediaData;
base::optional<SharedMediaWithLastSlice::Key> _sharedMediaDataKey; std::optional<SharedMediaWithLastSlice::Key> _sharedMediaDataKey;
std::unique_ptr<UserPhotos> _userPhotos; std::unique_ptr<UserPhotos> _userPhotos;
base::optional<UserPhotosSlice> _userPhotosData; std::optional<UserPhotosSlice> _userPhotosData;
QRect _closeNav, _closeNavIcon; QRect _closeNav, _closeNavIcon;
QRect _leftNav, _leftNavIcon, _rightNav, _rightNavIcon; QRect _leftNav, _leftNavIcon, _rightNav, _rightNavIcon;
@ -332,9 +332,9 @@ private:
PeerData *_from = nullptr; PeerData *_from = nullptr;
Text _fromName; Text _fromName;
base::optional<int> _index; // Index in current _sharedMedia data. std::optional<int> _index; // Index in current _sharedMedia data.
base::optional<int> _fullIndex; // Index in full shared media. std::optional<int> _fullIndex; // Index in full shared media.
base::optional<int> _fullCount; std::optional<int> _fullCount;
FullMsgId _msgid; FullMsgId _msgid;
bool _canForwardItem = false; bool _canForwardItem = false;
bool _canDeleteItem = false; bool _canDeleteItem = false;

View file

@ -969,8 +969,8 @@ void Messenger::unlockTerms() {
} }
} }
base::optional<Window::TermsLock> Messenger::termsLocked() const { std::optional<Window::TermsLock> Messenger::termsLocked() const {
return _termsLock ? base::make_optional(*_termsLock) : base::none; return _termsLock ? base::make_optional(*_termsLock) : std::nullopt;
} }
rpl::producer<bool> Messenger::termsLockChanges() const { rpl::producer<bool> Messenger::termsLockChanges() const {

View file

@ -177,7 +177,7 @@ public:
void lockByTerms(const Window::TermsLock &data); void lockByTerms(const Window::TermsLock &data);
void unlockTerms(); void unlockTerms();
[[nodiscard]] base::optional<Window::TermsLock> termsLocked() const; [[nodiscard]] std::optional<Window::TermsLock> termsLocked() const;
rpl::producer<bool> termsLockChanges() const; rpl::producer<bool> termsLockChanges() const;
rpl::producer<bool> termsLockValue() const; rpl::producer<bool> termsLockValue() const;
void termsDeleteNow(); void termsDeleteNow();

View file

@ -151,9 +151,9 @@ private:
void configLoadDone(const MTPConfig &result); void configLoadDone(const MTPConfig &result);
bool configLoadFail(const RPCError &error); bool configLoadFail(const RPCError &error);
base::optional<ShiftedDcId> queryRequestByDc( std::optional<ShiftedDcId> queryRequestByDc(
mtpRequestId requestId) const; mtpRequestId requestId) const;
base::optional<ShiftedDcId> changeRequestByDc( std::optional<ShiftedDcId> changeRequestByDc(
mtpRequestId requestId, DcId newdc); mtpRequestId requestId, DcId newdc);
// RPCError::NoError means do not toggle onError callback. // RPCError::NoError means do not toggle onError callback.
@ -806,17 +806,17 @@ bool Instance::Private::configLoadFail(const RPCError &error) {
return false; return false;
} }
base::optional<ShiftedDcId> Instance::Private::queryRequestByDc( std::optional<ShiftedDcId> Instance::Private::queryRequestByDc(
mtpRequestId requestId) const { mtpRequestId requestId) const {
QMutexLocker locker(&_requestByDcLock); QMutexLocker locker(&_requestByDcLock);
auto it = _requestsByDc.find(requestId); auto it = _requestsByDc.find(requestId);
if (it != _requestsByDc.cend()) { if (it != _requestsByDc.cend()) {
return it->second; return it->second;
} }
return base::none; return std::nullopt;
} }
base::optional<ShiftedDcId> Instance::Private::changeRequestByDc( std::optional<ShiftedDcId> Instance::Private::changeRequestByDc(
mtpRequestId requestId, mtpRequestId requestId,
DcId newdc) { DcId newdc) {
QMutexLocker locker(&_requestByDcLock); QMutexLocker locker(&_requestByDcLock);
@ -829,7 +829,7 @@ base::optional<ShiftedDcId> Instance::Private::changeRequestByDc(
} }
return it->second; return it->second;
} }
return base::none; return std::nullopt;
} }
void Instance::Private::checkDelayedRequests() { void Instance::Private::checkDelayedRequests() {

View file

@ -24,7 +24,7 @@ std::map<QString, QString> DeserializeData(bytes::const_span bytes);
struct DataError { struct DataError {
// QByteArray - bad existing scan with such file_hash // QByteArray - bad existing scan with such file_hash
// QString - bad data field value with such key // QString - bad data field value with such key
// base::none - additional scan required // std::nullopt - additional scan required
base::optional_variant<QByteArray, QString> key; base::optional_variant<QByteArray, QString> key;
QString type; // personal_details, passport, etc. QString type; // personal_details, passport, etc.
QString text; QString text;

View file

@ -559,7 +559,7 @@ const std::vector<EditFile> &Value::filesInEdit(FileType type) const {
Unexpected("Type in Value::filesInEdit() const."); Unexpected("Type in Value::filesInEdit() const.");
} }
EditFile &Value::fileInEdit(FileType type, base::optional<int> fileIndex) { EditFile &Value::fileInEdit(FileType type, std::optional<int> fileIndex) {
switch (type) { switch (type) {
case FileType::Scan: case FileType::Scan:
case FileType::Translation: { case FileType::Translation: {
@ -577,7 +577,7 @@ EditFile &Value::fileInEdit(FileType type, base::optional<int> fileIndex) {
const EditFile &Value::fileInEdit( const EditFile &Value::fileInEdit(
FileType type, FileType type,
base::optional<int> fileIndex) const { std::optional<int> fileIndex) const {
switch (type) { switch (type) {
case FileType::Scan: case FileType::Scan:
case FileType::Translation: { case FileType::Translation: {
@ -1232,7 +1232,7 @@ void FormController::fillNativeFromFallback() {
// Check if additional values should be copied from fallback values. // Check if additional values should be copied from fallback values.
const auto scheme = GetDocumentScheme( const auto scheme = GetDocumentScheme(
Scope::Type::PersonalDetails, Scope::Type::PersonalDetails,
base::none, std::nullopt,
true); true);
const auto dependencyIt = values.fields.find( const auto dependencyIt = values.fields.find(
scheme.additionalDependencyKey); scheme.additionalDependencyKey);
@ -1363,7 +1363,7 @@ void FormController::uploadScan(
return; return;
} }
const auto nonconst = findValue(value); const auto nonconst = findValue(value);
const auto fileIndex = [&]() -> base::optional<int> { const auto fileIndex = [&]() -> std::optional<int> {
auto scanInEdit = EditFile{ nonconst, type, File(), nullptr }; auto scanInEdit = EditFile{ nonconst, type, File(), nullptr };
if (type == FileType::Scan || type == FileType::Translation) { if (type == FileType::Scan || type == FileType::Translation) {
auto &list = nonconst->filesInEdit(type); auto &list = nonconst->filesInEdit(type);
@ -1379,7 +1379,7 @@ void FormController::uploadScan(
type, type,
std::move(scanInEdit)).first; std::move(scanInEdit)).first;
} }
return base::none; return std::nullopt;
}(); }();
auto &scan = nonconst->fileInEdit(type, fileIndex); auto &scan = nonconst->fileInEdit(type, fileIndex);
encryptFile(scan, std::move(content), [=](UploadScanData &&result) { encryptFile(scan, std::move(content), [=](UploadScanData &&result) {
@ -1392,14 +1392,14 @@ void FormController::uploadScan(
void FormController::deleteScan( void FormController::deleteScan(
not_null<const Value*> value, not_null<const Value*> value,
FileType type, FileType type,
base::optional<int> fileIndex) { std::optional<int> fileIndex) {
scanDeleteRestore(value, type, fileIndex, true); scanDeleteRestore(value, type, fileIndex, true);
} }
void FormController::restoreScan( void FormController::restoreScan(
not_null<const Value*> value, not_null<const Value*> value,
FileType type, FileType type,
base::optional<int> fileIndex) { std::optional<int> fileIndex) {
scanDeleteRestore(value, type, fileIndex, false); scanDeleteRestore(value, type, fileIndex, false);
} }
@ -1454,7 +1454,7 @@ void FormController::encryptFile(
void FormController::scanDeleteRestore( void FormController::scanDeleteRestore(
not_null<const Value*> value, not_null<const Value*> value,
FileType type, FileType type,
base::optional<int> fileIndex, std::optional<int> fileIndex,
bool deleted) { bool deleted) {
const auto nonconst = findValue(value); const auto nonconst = findValue(value);
auto &scan = nonconst->fileInEdit(type, fileIndex); auto &scan = nonconst->fileInEdit(type, fileIndex);
@ -1723,7 +1723,7 @@ void FormController::loadFile(File &file) {
file.id, file.id,
file.accessHash, file.accessHash,
QByteArray(), // file_reference QByteArray(), // file_reference
base::none, // origin std::nullopt, // origin
SecureFileLocation, SecureFileLocation,
QString(), QString(),
file.size, file.size,
@ -2299,10 +2299,10 @@ auto FormController::parseFiles(
auto FormController::parseFile( auto FormController::parseFile(
const MTPSecureFile &data, const MTPSecureFile &data,
const std::vector<EditFile> &editData) const const std::vector<EditFile> &editData) const
-> base::optional<File> { -> std::optional<File> {
switch (data.type()) { switch (data.type()) {
case mtpc_secureFileEmpty: case mtpc_secureFileEmpty:
return base::none; return std::nullopt;
case mtpc_secureFile: { case mtpc_secureFile: {
const auto &fields = data.c_secureFile(); const auto &fields = data.c_secureFile();

View file

@ -205,10 +205,10 @@ struct Value {
const QString &fileMissingError(FileType type) const; const QString &fileMissingError(FileType type) const;
std::vector<EditFile> &filesInEdit(FileType type); std::vector<EditFile> &filesInEdit(FileType type);
const std::vector<EditFile> &filesInEdit(FileType type) const; const std::vector<EditFile> &filesInEdit(FileType type) const;
EditFile &fileInEdit(FileType type, base::optional<int> fileIndex); EditFile &fileInEdit(FileType type, std::optional<int> fileIndex);
const EditFile &fileInEdit( const EditFile &fileInEdit(
FileType type, FileType type,
base::optional<int> fileIndex) const; std::optional<int> fileIndex) const;
std::vector<EditFile> takeAllFilesInEdit(); std::vector<EditFile> takeAllFilesInEdit();
@ -345,11 +345,11 @@ public:
void deleteScan( void deleteScan(
not_null<const Value*> value, not_null<const Value*> value,
FileType type, FileType type,
base::optional<int> fileIndex); std::optional<int> fileIndex);
void restoreScan( void restoreScan(
not_null<const Value*> value, not_null<const Value*> value,
FileType type, FileType type,
base::optional<int> fileIndex); std::optional<int> fileIndex);
rpl::producer<> secretReadyEvents() const; rpl::producer<> secretReadyEvents() const;
@ -407,7 +407,7 @@ private:
std::vector<File> parseFiles( std::vector<File> parseFiles(
const QVector<MTPSecureFile> &data, const QVector<MTPSecureFile> &data,
const std::vector<EditFile> &editData) const; const std::vector<EditFile> &editData) const;
base::optional<File> parseFile( std::optional<File> parseFile(
const MTPSecureFile &data, const MTPSecureFile &data,
const std::vector<EditFile> &editData) const; const std::vector<EditFile> &editData) const;
void fillDownloadedFile( void fillDownloadedFile(
@ -474,7 +474,7 @@ private:
void scanDeleteRestore( void scanDeleteRestore(
not_null<const Value*> value, not_null<const Value*> value,
FileType type, FileType type,
base::optional<int> fileIndex, std::optional<int> fileIndex,
bool deleted); bool deleted);
QString getPhoneFromValue(not_null<const Value*> value) const; QString getPhoneFromValue(not_null<const Value*> value) const;

View file

@ -376,7 +376,7 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
} }
const auto scheme = GetDocumentScheme( const auto scheme = GetDocumentScheme(
scope.type, scope.type,
document ? base::make_optional(document->type) : base::none, document ? base::make_optional(document->type) : std::nullopt,
scope.details ? scope.details->nativeNames : false); scope.details ? scope.details->nativeNames : false);
using ValueClass = EditDocumentScheme::ValueClass; using ValueClass = EditDocumentScheme::ValueClass;
const auto skipAdditional = [&] { const auto skipAdditional = [&] {

View file

@ -106,7 +106,7 @@ std::map<FileType, ScanInfo> PrepareSpecialFiles(const Value &value) {
EditDocumentScheme GetDocumentScheme( EditDocumentScheme GetDocumentScheme(
Scope::Type type, Scope::Type type,
base::optional<Value::Type> scansType, std::optional<Value::Type> scansType,
bool nativeNames) { bool nativeNames) {
using Scheme = EditDocumentScheme; using Scheme = EditDocumentScheme;
using ValueClass = Scheme::ValueClass; using ValueClass = Scheme::ValueClass;
@ -127,7 +127,7 @@ EditDocumentScheme GetDocumentScheme(
const auto FromBoolean = [](auto validation) { const auto FromBoolean = [](auto validation) {
return [=](const QString &value) { return [=](const QString &value) {
return validation(value) return validation(value)
? base::none ? std::nullopt
: base::make_optional(QString()); : base::make_optional(QString());
}; };
}; };
@ -136,7 +136,7 @@ EditDocumentScheme GetDocumentScheme(
return (value.size() >= min) && (value.size() <= max); return (value.size() >= min) && (value.size() <= max);
}); });
}; };
using Result = base::optional<QString>; using Result = std::optional<QString>;
const auto NameValidate = [](const QString &value) -> Result { const auto NameValidate = [](const QString &value) -> Result {
if (value.isEmpty() || value.size() > kMaxNameSize) { if (value.isEmpty() || value.size() > kMaxNameSize) {
return QString(); return QString();
@ -145,7 +145,7 @@ EditDocumentScheme GetDocumentScheme(
).match(value).hasMatch()) { ).match(value).hasMatch()) {
return lang(lng_passport_bad_name); return lang(lng_passport_bad_name);
} }
return base::none; return std::nullopt;
}; };
const auto NativeNameValidate = LimitedValidate(kMaxNameSize); const auto NativeNameValidate = LimitedValidate(kMaxNameSize);
const auto NativeNameOrEmptyValidate = LimitedValidate(kMaxNameSize, 0); const auto NativeNameOrEmptyValidate = LimitedValidate(kMaxNameSize, 0);
@ -174,7 +174,7 @@ EditDocumentScheme GetDocumentScheme(
}); });
const auto NameOrEmptyValidate = [=](const QString &value) -> Result { const auto NameOrEmptyValidate = [=](const QString &value) -> Result {
if (value.isEmpty()) { if (value.isEmpty()) {
return base::none; return std::nullopt;
} }
return NameValidate(value); return NameValidate(value);
}; };
@ -765,7 +765,7 @@ void PanelController::uploadScan(FileType type, QByteArray &&content) {
void PanelController::deleteScan( void PanelController::deleteScan(
FileType type, FileType type,
base::optional<int> fileIndex) { std::optional<int> fileIndex) {
Expects(_editScope != nullptr); Expects(_editScope != nullptr);
Expects(_editDocument != nullptr); Expects(_editDocument != nullptr);
Expects(_editDocument->requiresScan(type)); Expects(_editDocument->requiresScan(type));
@ -775,7 +775,7 @@ void PanelController::deleteScan(
void PanelController::restoreScan( void PanelController::restoreScan(
FileType type, FileType type,
base::optional<int> fileIndex) { std::optional<int> fileIndex) {
Expects(_editScope != nullptr); Expects(_editScope != nullptr);
Expects(_editDocument != nullptr); Expects(_editDocument != nullptr);
Expects(_editDocument->requiresScan(type)); Expects(_editDocument->requiresScan(type));
@ -808,13 +808,13 @@ std::vector<ScopeError> PanelController::collectSaveErrors(
} }
auto PanelController::deleteValueLabel() const auto PanelController::deleteValueLabel() const
-> base::optional<rpl::producer<QString>> { -> std::optional<rpl::producer<QString>> {
Expects(_editScope != nullptr); Expects(_editScope != nullptr);
if (hasValueDocument()) { if (hasValueDocument()) {
return Lang::Viewer(lng_passport_delete_document); return Lang::Viewer(lng_passport_delete_document);
} else if (!hasValueFields()) { } else if (!hasValueFields()) {
return base::none; return std::nullopt;
} }
switch (_editScope->type) { switch (_editScope->type) {
case Scope::Type::PersonalDetails: case Scope::Type::PersonalDetails:
@ -969,7 +969,7 @@ void PanelController::ensurePanelCreated() {
} }
} }
base::optional<int> PanelController::findBestDocumentIndex( std::optional<int> PanelController::findBestDocumentIndex(
const Scope &scope) const { const Scope &scope) const {
Expects(!scope.documents.empty()); Expects(!scope.documents.empty());
@ -981,7 +981,7 @@ base::optional<int> PanelController::findBestDocumentIndex(
return document->whatNotFilled(); return document->whatNotFilled();
}); });
return ((*i)->whatNotFilled() == Value::kNothingFilled) return ((*i)->whatNotFilled() == Value::kNothingFilled)
? base::none ? std::nullopt
: base::make_optional(int(i - begin(documents))); : base::make_optional(int(i - begin(documents)));
return -1; return -1;
} }
@ -992,7 +992,7 @@ void PanelController::editScope(int index) {
const auto &scope = _scopes[index]; const auto &scope = _scopes[index];
if (scope.documents.empty()) { if (scope.documents.empty()) {
editScope(index, base::none); editScope(index, std::nullopt);
} else { } else {
const auto documentIndex = findBestDocumentIndex(scope); const auto documentIndex = findBestDocumentIndex(scope);
if (documentIndex || scope.documents.size() == 1) { if (documentIndex || scope.documents.size() == 1) {
@ -1106,7 +1106,7 @@ void PanelController::readScanError(ReadScanError error) {
bool PanelController::editRequiresScanUpload( bool PanelController::editRequiresScanUpload(
int index, int index,
base::optional<int> documentIndex) const { std::optional<int> documentIndex) const {
Expects(index >= 0 && index < _scopes.size()); Expects(index >= 0 && index < _scopes.size());
Expects(!documentIndex Expects(!documentIndex
|| (*documentIndex >= 0 || (*documentIndex >= 0
@ -1125,7 +1125,7 @@ bool PanelController::editRequiresScanUpload(
void PanelController::editScope( void PanelController::editScope(
int index, int index,
base::optional<int> documentIndex) { std::optional<int> documentIndex) {
if (editRequiresScanUpload(index, documentIndex)) { if (editRequiresScanUpload(index, documentIndex)) {
editWithUpload(index, *documentIndex); editWithUpload(index, *documentIndex);
} else { } else {
@ -1135,7 +1135,7 @@ void PanelController::editScope(
void PanelController::startScopeEdit( void PanelController::startScopeEdit(
int index, int index,
base::optional<int> documentIndex) { std::optional<int> documentIndex) {
Expects(_panel != nullptr); Expects(_panel != nullptr);
Expects(index >= 0 && index < _scopes.size()); Expects(index >= 0 && index < _scopes.size());
Expects(_scopes[index].details != 0 || documentIndex.has_value()); Expects(_scopes[index].details != 0 || documentIndex.has_value());
@ -1168,7 +1168,7 @@ void PanelController::startScopeEdit(
? base::make_optional(PrepareScanListData( ? base::make_optional(PrepareScanListData(
*_editDocument, *_editDocument,
FileType::Translation)) FileType::Translation))
: base::none; : std::nullopt;
auto result = _editValue auto result = _editValue
? object_ptr<PanelEditDocument>( ? object_ptr<PanelEditDocument>(
_panel->widget(), _panel->widget(),
@ -1210,7 +1210,7 @@ void PanelController::startScopeEdit(
this, this,
GetDocumentScheme( GetDocumentScheme(
_editScope->type, _editScope->type,
base::none, std::nullopt,
_editValue->nativeNames), _editValue->nativeNames),
_editValue->error, _editValue->error,
_editValue->data.parsedInEdit); _editValue->data.parsedInEdit);

View file

@ -22,7 +22,7 @@ enum class ReadScanError;
EditDocumentScheme GetDocumentScheme( EditDocumentScheme GetDocumentScheme(
Scope::Type type, Scope::Type type,
base::optional<Value::Type> scansType, std::optional<Value::Type> scansType,
bool nativeNames); bool nativeNames);
EditContactScheme GetContactScheme(Scope::Type type); EditContactScheme GetContactScheme(Scope::Type type);
@ -98,13 +98,13 @@ public:
bool canAddScan(FileType type) const; bool canAddScan(FileType type) const;
void uploadScan(FileType type, QByteArray &&content); void uploadScan(FileType type, QByteArray &&content);
void deleteScan(FileType type, base::optional<int> fileIndex); void deleteScan(FileType type, std::optional<int> fileIndex);
void restoreScan(FileType type, base::optional<int> fileIndex); void restoreScan(FileType type, std::optional<int> fileIndex);
rpl::producer<ScanInfo> scanUpdated() const; rpl::producer<ScanInfo> scanUpdated() const;
rpl::producer<ScopeError> saveErrors() const; rpl::producer<ScopeError> saveErrors() const;
void readScanError(ReadScanError error); void readScanError(ReadScanError error);
base::optional<rpl::producer<QString>> deleteValueLabel() const; std::optional<rpl::producer<QString>> deleteValueLabel() const;
void deleteValue(); void deleteValue();
QString defaultEmail() const; QString defaultEmail() const;
@ -149,13 +149,13 @@ public:
private: private:
void ensurePanelCreated(); void ensurePanelCreated();
void editScope(int index, base::optional<int> documentIndex); void editScope(int index, std::optional<int> documentIndex);
void editWithUpload(int index, int documentIndex); void editWithUpload(int index, int documentIndex);
bool editRequiresScanUpload( bool editRequiresScanUpload(
int index, int index,
base::optional<int> documentIndex) const; std::optional<int> documentIndex) const;
void startScopeEdit(int index, base::optional<int> documentIndex); void startScopeEdit(int index, std::optional<int> documentIndex);
base::optional<int> findBestDocumentIndex(const Scope &scope) const; std::optional<int> findBestDocumentIndex(const Scope &scope) const;
void requestScopeFilesType(int index); void requestScopeFilesType(int index);
void cancelValueEdit(); void cancelValueEdit();
void processValueSaveFinished(not_null<const Value*> value); void processValueSaveFinished(not_null<const Value*> value);

View file

@ -225,7 +225,7 @@ private:
Female, Female,
}; };
static base::optional<Gender> StringToGender(const QString &value); static std::optional<Gender> StringToGender(const QString &value);
static QString GenderToString(Gender gender); static QString GenderToString(Gender gender);
int resizeInner(int left, int top, int width) override; int resizeInner(int left, int top, int width) override;
@ -366,7 +366,7 @@ void CountryRow::toggleError(bool shown) {
void CountryRow::errorAnimationCallback() { void CountryRow::errorAnimationCallback() {
const auto error = _errorAnimation.current(_errorShown ? 1. : 0.); const auto error = _errorAnimation.current(_errorShown ? 1. : 0.);
if (error == 0.) { if (error == 0.) {
_link->setColorOverride(base::none); _link->setColorOverride(std::nullopt);
} else { } else {
_link->setColorOverride(anim::color( _link->setColorOverride(anim::color(
st::boxLinkButton.color, st::boxLinkButton.color,
@ -877,13 +877,13 @@ std::unique_ptr<Ui::AbstractCheckView> GenderRow::createRadioView(
} }
auto GenderRow::StringToGender(const QString &value) auto GenderRow::StringToGender(const QString &value)
-> base::optional<Gender> { -> std::optional<Gender> {
if (value == qstr("male")) { if (value == qstr("male")) {
return Gender::Male; return Gender::Male;
} else if (value == qstr("female")) { } else if (value == qstr("female")) {
return Gender::Female; return Gender::Female;
} }
return base::none; return std::nullopt;
} }
QString GenderRow::GenderToString(Gender gender) { QString GenderRow::GenderToString(Gender gender) {
@ -936,8 +936,8 @@ void GenderRow::toggleError(bool shown) {
void GenderRow::errorAnimationCallback() { void GenderRow::errorAnimationCallback() {
const auto error = _errorAnimation.current(_errorShown ? 1. : 0.); const auto error = _errorAnimation.current(_errorShown ? 1. : 0.);
if (error == 0.) { if (error == 0.) {
_maleRadio->setUntoggledOverride(base::none); _maleRadio->setUntoggledOverride(std::nullopt);
_femaleRadio->setUntoggledOverride(base::none); _femaleRadio->setUntoggledOverride(std::nullopt);
} else { } else {
const auto color = anim::color( const auto color = anim::color(
st::defaultRadio.untoggledFg, st::defaultRadio.untoggledFg,
@ -1041,7 +1041,7 @@ int PanelDetailsRow::resizeGetHeight(int newWidth) {
return result; return result;
} }
void PanelDetailsRow::showError(base::optional<QString> error) { void PanelDetailsRow::showError(std::optional<QString> error) {
if (!_errorHideSubscription) { if (!_errorHideSubscription) {
_errorHideSubscription = true; _errorHideSubscription = true;

View file

@ -54,7 +54,7 @@ public:
virtual bool setFocusFast(); virtual bool setFocusFast();
virtual rpl::producer<QString> value() const = 0; virtual rpl::producer<QString> value() const = 0;
virtual QString valueCurrent() const = 0; virtual QString valueCurrent() const = 0;
void showError(base::optional<QString> error = base::none); void showError(std::optional<QString> error = std::nullopt);
bool errorShown() const; bool errorShown() const;
void hideError(); void hideError();
void finishAnimating(); void finishAnimating();

View file

@ -215,7 +215,7 @@ PanelEditDocument::PanelEditDocument(
const QString &scansError, const QString &scansError,
const ValueMap &scansData, const ValueMap &scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles) std::map<FileType, ScanInfo> &&specialFiles)
: _controller(controller) : _controller(controller)
, _scheme(std::move(scheme)) , _scheme(std::move(scheme))
@ -243,7 +243,7 @@ PanelEditDocument::PanelEditDocument(
const QString &scansError, const QString &scansError,
const ValueMap &scansData, const ValueMap &scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles) std::map<FileType, ScanInfo> &&specialFiles)
: _controller(controller) : _controller(controller)
, _scheme(std::move(scheme)) , _scheme(std::move(scheme))
@ -288,7 +288,7 @@ void PanelEditDocument::setupControls(
const QString *scansError, const QString *scansError,
const ValueMap *scansData, const ValueMap *scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles) { std::map<FileType, ScanInfo> &&specialFiles) {
const auto inner = setupContent( const auto inner = setupContent(
error, error,
@ -316,7 +316,7 @@ not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
const QString *scansError, const QString *scansError,
const ValueMap *scansData, const ValueMap *scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles) { std::map<FileType, ScanInfo> &&specialFiles) {
const auto inner = _scroll->setOwnedWidget( const auto inner = _scroll->setOwnedWidget(
object_ptr<Ui::VerticalLayout>(this)); object_ptr<Ui::VerticalLayout>(this));
@ -629,7 +629,7 @@ void PanelEditDocument::fillAdditionalFromFallbacks(Result &result) const {
bool PanelEditDocument::validate() { bool PanelEditDocument::validate() {
auto error = _editScans auto error = _editScans
? _editScans->validateGetErrorTop() ? _editScans->validateGetErrorTop()
: base::none; : std::nullopt;
if (error) { if (error) {
const auto errortop = _editScans->mapToGlobal(QPoint(0, *error)); const auto errortop = _editScans->mapToGlobal(QPoint(0, *error));
const auto scrolltop = _scroll->mapToGlobal(QPoint(0, 0)); const auto scrolltop = _scroll->mapToGlobal(QPoint(0, 0));

View file

@ -50,7 +50,7 @@ struct EditDocumentScheme {
Shown, Shown,
}; };
struct Row { struct Row {
using Validator = Fn<base::optional<QString>(const QString &value)>; using Validator = Fn<std::optional<QString>(const QString &value)>;
using Formatter = Fn<QString(const QString &value)>; using Formatter = Fn<QString(const QString &value)>;
ValueClass valueClass = ValueClass::Fields; ValueClass valueClass = ValueClass::Fields;
PanelDetailsType inputType = PanelDetailsType(); PanelDetailsType inputType = PanelDetailsType();
@ -87,7 +87,7 @@ public:
const QString &scansError, const QString &scansError,
const ValueMap &scansData, const ValueMap &scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles); std::map<FileType, ScanInfo> &&specialFiles);
PanelEditDocument( PanelEditDocument(
QWidget *parent, QWidget *parent,
@ -96,7 +96,7 @@ public:
const QString &scansError, const QString &scansError,
const ValueMap &scansData, const ValueMap &scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles); std::map<FileType, ScanInfo> &&specialFiles);
PanelEditDocument( PanelEditDocument(
QWidget *parent, QWidget *parent,
@ -119,7 +119,7 @@ private:
const QString *scansError, const QString *scansError,
const ValueMap *scansData, const ValueMap *scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles); std::map<FileType, ScanInfo> &&specialFiles);
not_null<Ui::RpWidget*> setupContent( not_null<Ui::RpWidget*> setupContent(
const QString *error, const QString *error,
@ -127,7 +127,7 @@ private:
const QString *scansError, const QString *scansError,
const ValueMap *scansData, const ValueMap *scansData,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations, std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles); std::map<FileType, ScanInfo> &&specialFiles);
void updateControlsGeometry(); void updateControlsGeometry();
void updateCommonError(); void updateCommonError();

View file

@ -160,10 +160,10 @@ EditScans::List::List(
EditScans::List::List( EditScans::List::List(
not_null<PanelController*> controller, not_null<PanelController*> controller,
base::optional<ScanListData> &&data) std::optional<ScanListData> &&data)
: controller(controller) : controller(controller)
, files(data ? std::move(data->files) : std::vector<ScanInfo>()) , files(data ? std::move(data->files) : std::vector<ScanInfo>())
, initialCount(data ? base::make_optional(int(files.size())) : base::none) , initialCount(data ? base::make_optional(int(files.size())) : std::nullopt)
, errorMissing(data ? std::move(data->errorMissing) : QString()) { , errorMissing(data ? std::move(data->errorMissing) : QString()) {
} }
@ -232,7 +232,7 @@ void EditScans::List::toggleError(bool shown) {
void EditScans::List::errorAnimationCallback() { void EditScans::List::errorAnimationCallback() {
const auto error = errorAnimation.current(errorShown ? 1. : 0.); const auto error = errorAnimation.current(errorShown ? 1. : 0.);
if (error == 0.) { if (error == 0.) {
upload->setColorOverride(base::none); upload->setColorOverride(std::nullopt);
} else { } else {
upload->setColorOverride(anim::color( upload->setColorOverride(anim::color(
st::passportUploadButton.textFg, st::passportUploadButton.textFg,
@ -428,7 +428,7 @@ EditScans::EditScans(
const QString &header, const QString &header,
const QString &error, const QString &error,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations) std::optional<ScanListData> &&translations)
: RpWidget(parent) : RpWidget(parent)
, _controller(controller) , _controller(controller)
, _error(error) , _error(error)
@ -444,7 +444,7 @@ EditScans::EditScans(
const QString &header, const QString &header,
const QString &error, const QString &error,
std::map<FileType, ScanInfo> &&specialFiles, std::map<FileType, ScanInfo> &&specialFiles,
base::optional<ScanListData> &&translations) std::optional<ScanListData> &&translations)
: RpWidget(parent) : RpWidget(parent)
, _controller(controller) , _controller(controller)
, _error(error) , _error(error)
@ -454,8 +454,8 @@ EditScans::EditScans(
setupSpecialScans(header, std::move(specialFiles)); setupSpecialScans(header, std::move(specialFiles));
} }
base::optional<int> EditScans::validateGetErrorTop() { std::optional<int> EditScans::validateGetErrorTop() {
auto result = base::optional<int>(); auto result = std::optional<int>();
const auto suggestResult = [&](int value) { const auto suggestResult = [&](int value) {
if (!result || *result > value) { if (!result || *result > value) {
result = value; result = value;
@ -828,12 +828,12 @@ void EditScans::createSpecialScanRow(
row->deleteClicks( row->deleteClicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
_controller->deleteScan(type, base::none); _controller->deleteScan(type, std::nullopt);
}, row->lifetime()); }, row->lifetime());
row->restoreClicks( row->restoreClicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
_controller->restoreScan(type, base::none); _controller->restoreScan(type, std::nullopt);
}, row->lifetime()); }, row->lifetime());
scan.rowCreated = !info.deleted; scan.rowCreated = !info.deleted;
@ -974,7 +974,7 @@ void EditScans::specialScanErrorAnimationCallback(FileType type) {
const auto error = scan.errorAnimation.current( const auto error = scan.errorAnimation.current(
scan.errorShown ? 1. : 0.); scan.errorShown ? 1. : 0.);
if (error == 0.) { if (error == 0.) {
scan.upload->setColorOverride(base::none); scan.upload->setColorOverride(std::nullopt);
} else { } else {
scan.upload->setColorOverride(anim::color( scan.upload->setColorOverride(anim::color(
st::passportUploadButton.textFg, st::passportUploadButton.textFg,

View file

@ -51,16 +51,16 @@ public:
const QString &header, const QString &header,
const QString &error, const QString &error,
ScanListData &&scans, ScanListData &&scans,
base::optional<ScanListData> &&translations); std::optional<ScanListData> &&translations);
EditScans( EditScans(
QWidget *parent, QWidget *parent,
not_null<PanelController*> controller, not_null<PanelController*> controller,
const QString &header, const QString &header,
const QString &error, const QString &error,
std::map<FileType, ScanInfo> &&specialFiles, std::map<FileType, ScanInfo> &&specialFiles,
base::optional<ScanListData> &&translations); std::optional<ScanListData> &&translations);
base::optional<int> validateGetErrorTop(); std::optional<int> validateGetErrorTop();
void scanFieldsChanged(bool changed); void scanFieldsChanged(bool changed);
@ -78,7 +78,7 @@ private:
List(not_null<PanelController*> controller, ScanListData &&data); List(not_null<PanelController*> controller, ScanListData &&data);
List( List(
not_null<PanelController*> controller, not_null<PanelController*> controller,
base::optional<ScanListData> &&data = base::none); std::optional<ScanListData> &&data = std::nullopt);
bool uploadedSomeMore() const; bool uploadedSomeMore() const;
bool uploadMoreRequired() const; bool uploadMoreRequired() const;
@ -92,7 +92,7 @@ private:
not_null<PanelController*> controller; not_null<PanelController*> controller;
std::vector<ScanInfo> files; std::vector<ScanInfo> files;
base::optional<int> initialCount; std::optional<int> initialCount;
QString errorMissing; QString errorMissing;
QPointer<Ui::SlideWrap<BoxContentDivider>> divider; QPointer<Ui::SlideWrap<BoxContentDivider>> divider;
QPointer<Ui::SlideWrap<Ui::FlatLabel>> header; QPointer<Ui::SlideWrap<Ui::FlatLabel>> header;

View file

@ -29,7 +29,7 @@ namespace {
constexpr auto kIgnoreActivationTimeoutMs = 500; constexpr auto kIgnoreActivationTimeoutMs = 500;
base::optional<bool> ApplicationIsActive; std::optional<bool> ApplicationIsActive;
} // namespace } // namespace

View file

@ -40,7 +40,7 @@ Launcher::Launcher(int argc, char *argv[])
: Core::Launcher(argc, argv, DeviceModel(), SystemVersion()) { : Core::Launcher(argc, argv, DeviceModel(), SystemVersion()) {
} }
base::optional<QStringList> Launcher::readArgumentsHook( std::optional<QStringList> Launcher::readArgumentsHook(
int argc, int argc,
char *argv[]) const { char *argv[]) const {
auto count = 0; auto count = 0;
@ -55,7 +55,7 @@ base::optional<QStringList> Launcher::readArgumentsHook(
return result; return result;
} }
} }
return base::none; return std::nullopt;
} }
bool Launcher::launchUpdater(UpdaterLaunch action) { bool Launcher::launchUpdater(UpdaterLaunch action) {

View file

@ -16,7 +16,7 @@ public:
Launcher(int argc, char *argv[]); Launcher(int argc, char *argv[]);
private: private:
base::optional<QStringList> readArgumentsHook( std::optional<QStringList> readArgumentsHook(
int argc, int argc,
char *argv[]) const override; char *argv[]) const override;

View file

@ -21,17 +21,17 @@ namespace details {
template <typename ...Values> template <typename ...Values>
struct combine_state { struct combine_state {
combine_state() : accumulated(std::tuple<base::optional<Values>...>()) { combine_state() : accumulated(std::tuple<std::optional<Values>...>()) {
} }
base::optional<std::tuple<base::optional<Values>...>> accumulated; std::optional<std::tuple<std::optional<Values>...>> accumulated;
base::optional<std::tuple<Values...>> latest; std::optional<std::tuple<Values...>> latest;
int invalid = sizeof...(Values); int invalid = sizeof...(Values);
int working = sizeof...(Values); int working = sizeof...(Values);
}; };
template <typename ...Values, std::size_t ...I> template <typename ...Values, std::size_t ...I>
inline std::tuple<Values...> combine_make_first( inline std::tuple<Values...> combine_make_first(
std::tuple<base::optional<Values>...> &&accumulated, std::tuple<std::optional<Values>...> &&accumulated,
std::index_sequence<I...>) { std::index_sequence<I...>) {
return std::make_tuple(std::move(*std::get<I>(accumulated))...); return std::make_tuple(std::move(*std::get<I>(accumulated))...);
} }
@ -65,7 +65,7 @@ public:
state->latest = combine_make_first( state->latest = combine_make_first(
std::move(*state->accumulated), std::move(*state->accumulated),
std::make_index_sequence<kArity>()); std::make_index_sequence<kArity>());
state->accumulated = base::none; state->accumulated = std::nullopt;
consumer.put_next_copy(*state->latest); consumer.put_next_copy(*state->latest);
} }
} }
@ -276,7 +276,7 @@ namespace details {
template <typename Value> template <typename Value>
struct combine_vector_state { struct combine_vector_state {
std::vector<base::optional<Value>> accumulated; std::vector<std::optional<Value>> accumulated;
std::vector<Value> latest; std::vector<Value> latest;
int invalid = 0; int invalid = 0;
int working = 0; int working = 0;

View file

@ -22,7 +22,7 @@ public:
initial = std::move(initial) initial = std::move(initial)
](const auto &consumer) mutable { ](const auto &consumer) mutable {
auto previous = consumer.template make_state< auto previous = consumer.template make_state<
base::optional<Value> std::optional<Value>
>(); >();
return std::move(initial).start( return std::move(initial).start(
[consumer, previous](auto &&value) { [consumer, previous](auto &&value) {

View file

@ -22,7 +22,7 @@ public:
initial = std::move(initial) initial = std::move(initial)
](const auto &consumer) mutable { ](const auto &consumer) mutable {
auto previous = consumer.template make_state< auto previous = consumer.template make_state<
base::optional<Value> std::optional<Value>
>(); >();
return std::move(initial).start( return std::move(initial).start(
[consumer, previous](auto &&value) { [consumer, previous](auto &&value) {

View file

@ -95,13 +95,13 @@ private:
template <typename Value> template <typename Value>
inline const Value &deref_optional_helper( inline const Value &deref_optional_helper(
const base::optional<Value> &value) { const std::optional<Value> &value) {
return *value; return *value;
} }
template <typename Value> template <typename Value>
inline Value &&deref_optional_helper( inline Value &&deref_optional_helper(
base::optional<Value> &&value) { std::optional<Value> &&value) {
return std::move(*value); return std::move(*value);
} }
@ -109,7 +109,7 @@ class filter_optional_helper {
public: public:
template <typename Value, typename Error, typename Generator> template <typename Value, typename Error, typename Generator>
auto operator()(producer< auto operator()(producer<
base::optional<Value>, std::optional<Value>,
Error, Error,
Generator> &&initial) const { Generator> &&initial) const {
return make_producer<Value, Error>([ return make_producer<Value, Error>([

View file

@ -55,6 +55,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <unordered_set> #include <unordered_set>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <optional>
#include <range/v3/all.hpp> #include <range/v3/all.hpp>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

View file

@ -30,7 +30,7 @@ bool BinlogWrapper::failed() const {
return _failed; return _failed;
} }
base::optional<BasicHeader> BinlogWrapper::ReadHeader( std::optional<BasicHeader> BinlogWrapper::ReadHeader(
File &binlog, File &binlog,
const Settings &settings) { const Settings &settings) {
auto result = BasicHeader(); auto result = BasicHeader();

View file

@ -26,7 +26,7 @@ public:
bool finished() const; bool finished() const;
bool failed() const; bool failed() const;
static base::optional<BasicHeader> ReadHeader( static std::optional<BasicHeader> ReadHeader(
File &binlog, File &binlog,
const Settings &settings); const Settings &settings);

View file

@ -814,7 +814,7 @@ void DatabaseObject::put(
} }
template <typename StoreRecord> template <typename StoreRecord>
base::optional<QString> DatabaseObject::writeKeyPlaceGeneric( std::optional<QString> DatabaseObject::writeKeyPlaceGeneric(
StoreRecord &&record, StoreRecord &&record,
const Key &key, const Key &key,
const TaggedValue &value, const TaggedValue &value,
@ -856,7 +856,7 @@ base::optional<QString> DatabaseObject::writeKeyPlaceGeneric(
return result; return result;
} }
base::optional<QString> DatabaseObject::writeKeyPlace( std::optional<QString> DatabaseObject::writeKeyPlace(
const Key &key, const Key &key,
const TaggedValue &data, const TaggedValue &data,
uint32 checksum) { uint32 checksum) {

View file

@ -187,12 +187,12 @@ private:
bool isFreePlace(PlaceId place) const; bool isFreePlace(PlaceId place) const;
template <typename StoreRecord> template <typename StoreRecord>
base::optional<QString> writeKeyPlaceGeneric( std::optional<QString> writeKeyPlaceGeneric(
StoreRecord &&record, StoreRecord &&record,
const Key &key, const Key &key,
const TaggedValue &value, const TaggedValue &value,
uint32 checksum); uint32 checksum);
base::optional<QString> writeKeyPlace( std::optional<QString> writeKeyPlace(
const Key &key, const Key &key,
const TaggedValue &value, const TaggedValue &value,
uint32 checksum); uint32 checksum);

View file

@ -59,14 +59,14 @@ QString VersionFilePath(const QString &base) {
return base + QStringLiteral("version"); return base + QStringLiteral("version");
} }
base::optional<Version> ReadVersionValue(const QString &base) { std::optional<Version> ReadVersionValue(const QString &base) {
QFile file(VersionFilePath(base)); QFile file(VersionFilePath(base));
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
return base::none; return std::nullopt;
} }
const auto bytes = file.read(sizeof(Version)); const auto bytes = file.read(sizeof(Version));
if (bytes.size() != sizeof(Version)) { if (bytes.size() != sizeof(Version)) {
return base::none; return std::nullopt;
} }
return *reinterpret_cast<const Version*>(bytes.data()); return *reinterpret_cast<const Version*>(bytes.data());
} }

View file

@ -111,7 +111,7 @@ using Version = int32;
QString ComputeBasePath(const QString &original); QString ComputeBasePath(const QString &original);
QString VersionFilePath(const QString &base); QString VersionFilePath(const QString &base);
base::optional<Version> ReadVersionValue(const QString &base); std::optional<Version> ReadVersionValue(const QString &base);
bool WriteVersionValue(const QString &base, Version value); bool WriteVersionValue(const QString &base, Version value);
template <typename Record> template <typename Record>

View file

@ -1110,7 +1110,7 @@ void mtpFileLoader::changeCDNParams(
makeRequest(offset); makeRequest(offset);
} }
base::optional<Storage::Cache::Key> mtpFileLoader::cacheKey() const { std::optional<Storage::Cache::Key> mtpFileLoader::cacheKey() const {
if (_urlLocation) { if (_urlLocation) {
return Data::WebDocumentCacheKey(*_urlLocation); return Data::WebDocumentCacheKey(*_urlLocation);
} else if (_location) { } else if (_location) {
@ -1118,7 +1118,7 @@ base::optional<Storage::Cache::Key> mtpFileLoader::cacheKey() const {
} else if (_toCache == LoadToCacheAsWell) { } else if (_toCache == LoadToCacheAsWell) {
return Data::DocumentCacheKey(_dcId, _id); return Data::DocumentCacheKey(_dcId, _id);
} }
return base::none; return std::nullopt;
} }
mtpFileLoader::~mtpFileLoader() { mtpFileLoader::~mtpFileLoader() {
@ -1219,7 +1219,7 @@ void webFileLoader::onError() {
cancel(true); cancel(true);
} }
base::optional<Storage::Cache::Key> webFileLoader::cacheKey() const { std::optional<Storage::Cache::Key> webFileLoader::cacheKey() const {
return Data::UrlCacheKey(_url); return Data::UrlCacheKey(_url);
} }

View file

@ -153,7 +153,7 @@ protected:
bool tryLoadLocal(); bool tryLoadLocal();
void loadLocal(const Storage::Cache::Key &key); void loadLocal(const Storage::Cache::Key &key);
virtual base::optional<Storage::Cache::Key> cacheKey() const = 0; virtual std::optional<Storage::Cache::Key> cacheKey() const = 0;
virtual void cancelRequests() = 0; virtual void cancelRequests() = 0;
void startLoading(bool loadFirst, bool prior); void startLoading(bool loadFirst, bool prior);
@ -257,7 +257,7 @@ private:
int limit = 0; int limit = 0;
QByteArray hash; QByteArray hash;
}; };
base::optional<Storage::Cache::Key> cacheKey() const override; std::optional<Storage::Cache::Key> cacheKey() const override;
void cancelRequests() override; void cancelRequests() override;
int partSize() const; int partSize() const;
@ -346,7 +346,7 @@ public:
protected: protected:
void cancelRequests() override; void cancelRequests() override;
base::optional<Storage::Cache::Key> cacheKey() const override; std::optional<Storage::Cache::Key> cacheKey() const override;
bool loadPart() override; bool loadPart() override;
QString _url; QString _url;

View file

@ -165,7 +165,7 @@ struct SendingAlbum {
} }
TaskId taskId; TaskId taskId;
FullMsgId msgId; FullMsgId msgId;
base::optional<MTPInputSingleMedia> media; std::optional<MTPInputSingleMedia> media;
}; };
SendingAlbum(); SendingAlbum();

View file

@ -4232,7 +4232,7 @@ void incrementRecentHashtag(RecentHashtagPack &recent, const QString &tag) {
} }
} }
base::optional<RecentHashtagPack> saveRecentHashtags( std::optional<RecentHashtagPack> saveRecentHashtags(
Fn<RecentHashtagPack()> getPack, Fn<RecentHashtagPack()> getPack,
const QString &text) { const QString &text) {
auto found = false; auto found = false;
@ -4262,7 +4262,7 @@ base::optional<RecentHashtagPack> saveRecentHashtags(
found = true; found = true;
incrementRecentHashtag(recent, tag); incrementRecentHashtag(recent, tag);
} }
return found ? base::make_optional(recent) : base::none; return found ? base::make_optional(recent) : std::nullopt;
} }
void saveRecentSentHashtags(const QString &text) { void saveRecentSentHashtags(const QString &text) {

View file

@ -295,7 +295,7 @@ void File::close() {
_data.close(); _data.close();
_data.setFileName(QString()); _data.setFileName(QString());
_dataSize = _encryptionOffset = 0; _dataSize = _encryptionOffset = 0;
_state = base::none; _state = std::nullopt;
} }
bool File::isOpen() const { bool File::isOpen() const {

View file

@ -66,7 +66,7 @@ private:
int64 _encryptionOffset = 0; int64 _encryptionOffset = 0;
int64 _dataSize = 0; int64 _dataSize = 0;
base::optional<CtrState> _state; std::optional<CtrState> _state;
}; };

View file

@ -36,7 +36,7 @@ void FeedMessages::add(FeedMessagesAddSlice &&query) {
feedIt->second.addSlice( feedIt->second.addSlice(
std::move(query.messageIds), std::move(query.messageIds),
query.noSkipRange, query.noSkipRange,
base::none); std::nullopt);
} }
void FeedMessages::remove(FeedMessagesRemoveOne &&query) { void FeedMessages::remove(FeedMessagesRemoveOne &&query) {

View file

@ -73,7 +73,7 @@ struct SharedMediaAddSlice {
SharedMediaType type, SharedMediaType type,
std::vector<MsgId> &&messageIds, std::vector<MsgId> &&messageIds,
MsgRange noSkipRange, MsgRange noSkipRange,
base::optional<int> count = base::none) std::optional<int> count = std::nullopt)
: peerId(peerId) : peerId(peerId)
, messageIds(std::move(messageIds)) , messageIds(std::move(messageIds))
, noSkipRange(noSkipRange) , noSkipRange(noSkipRange)
@ -85,7 +85,7 @@ struct SharedMediaAddSlice {
std::vector<MsgId> messageIds; std::vector<MsgId> messageIds;
MsgRange noSkipRange; MsgRange noSkipRange;
SharedMediaType type = SharedMediaType::kCount; SharedMediaType type = SharedMediaType::kCount;
base::optional<int> count; std::optional<int> count;
}; };

Some files were not shown because too many files have changed in this diff Show more