Replace boost::optional with std::optional (#4877)

This commit is contained in:
pajlada
2023-10-08 18:50:48 +02:00
committed by GitHub
parent fe4d6121a2
commit fec45889a8
88 changed files with 428 additions and 383 deletions
@@ -114,7 +114,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
const auto &bttvemotes = app->twitch->getBttvEmotes();
const auto &ffzemotes = app->twitch->getFfzEmotes();
auto flags = MessageElementFlags();
auto emote = boost::optional<EmotePtr>{};
auto emote = std::optional<EmotePtr>{};
for (int i = 2; i < words.length(); i++)
{
{ // Twitch emote
@@ -138,7 +138,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
}
if (emote)
{
b.emplace<EmoteElement>(emote.get(), flags);
b.emplace<EmoteElement>(*emote, flags);
continue;
}
} // bttv/ffz emote
@@ -181,7 +181,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
app->twitch->whispersChannel->addMessage(messagexD);
auto overrideFlags = boost::optional<MessageFlags>(messagexD->flags);
auto overrideFlags = std::optional<MessageFlags>(messagexD->flags);
overrideFlags->set(MessageFlag::DoNotLog);
if (getSettings()->inlineWhispers &&
@@ -2856,7 +2856,7 @@ void CommandController::initialize(Settings &, Paths &paths)
formatBanTimeoutError](const auto &targetUser) {
getHelix()->banUser(
twitchChannel->roomId(), currentUser->getUserId(),
targetUser.id, boost::none, reason,
targetUser.id, std::nullopt, reason,
[] {
// No response for bans, they're emitted over pubsub/IRC instead
},
@@ -2910,7 +2910,7 @@ void CommandController::initialize(Settings &, Paths &paths)
getHelix()->banUser(
twitchChannel->roomId(), currentUser->getUserId(), target,
boost::none, reason,
std::nullopt, reason,
[] {
// No response for bans, they're emitted over pubsub/IRC instead
},
@@ -289,7 +289,7 @@ QString slowOff(const CommandContext &ctx)
}
getHelix()->updateSlowMode(ctx.twitchChannel->roomId(),
currentUser->getUserId(), boost::none,
currentUser->getUserId(), std::nullopt,
successCallback, failureCallback(ctx.channel));
return "";
@@ -367,7 +367,7 @@ QString followersOff(const CommandContext &ctx)
}
getHelix()->updateFollowerMode(
ctx.twitchChannel->roomId(), currentUser->getUserId(), boost::none,
ctx.twitchChannel->roomId(), currentUser->getUserId(), std::nullopt,
successCallback, failureCallback(ctx.channel));
return "";
@@ -23,7 +23,7 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck
[highlight](const auto &args, const auto &badges,
const auto &senderName, const auto &originalMessage,
const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
(void)args; // unused
(void)badges; // unused
(void)senderName; // unused
@@ -32,15 +32,15 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck
if (self)
{
// Phrase checks should ignore highlights from the user
return boost::none;
return std::nullopt;
}
if (!highlight.isMatch(originalMessage))
{
return boost::none;
return std::nullopt;
}
boost::optional<QUrl> highlightSoundUrl;
std::optional<QUrl> highlightSoundUrl;
if (highlight.hasCustomSound())
{
highlightSoundUrl = highlight.getSoundUrl();
@@ -62,7 +62,7 @@ void rebuildSubscriptionHighlights(Settings &settings,
auto highlightSound = settings.enableSubHighlightSound.getValue();
auto highlightAlert = settings.enableSubHighlightTaskbar.getValue();
auto highlightSoundUrlValue = settings.subHighlightSoundUrl.getValue();
boost::optional<QUrl> highlightSoundUrl;
std::optional<QUrl> highlightSoundUrl;
if (!highlightSoundUrlValue.isEmpty())
{
highlightSoundUrl = highlightSoundUrlValue;
@@ -73,7 +73,7 @@ void rebuildSubscriptionHighlights(Settings &settings,
checks.emplace_back(HighlightCheck{
[=](const auto &args, const auto &badges, const auto &senderName,
const auto &originalMessage, const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
(void)badges; // unused
(void)senderName; // unused
(void)originalMessage; // unused
@@ -82,7 +82,7 @@ void rebuildSubscriptionHighlights(Settings &settings,
if (!args.isSubscriptionMessage)
{
return boost::none;
return std::nullopt;
}
auto highlightColor =
@@ -108,7 +108,7 @@ void rebuildWhisperHighlights(Settings &settings,
auto highlightAlert = settings.enableWhisperHighlightTaskbar.getValue();
auto highlightSoundUrlValue =
settings.whisperHighlightSoundUrl.getValue();
boost::optional<QUrl> highlightSoundUrl;
std::optional<QUrl> highlightSoundUrl;
if (!highlightSoundUrlValue.isEmpty())
{
highlightSoundUrl = highlightSoundUrlValue;
@@ -119,7 +119,7 @@ void rebuildWhisperHighlights(Settings &settings,
checks.emplace_back(HighlightCheck{
[=](const auto &args, const auto &badges, const auto &senderName,
const auto &originalMessage, const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
(void)badges; // unused
(void)senderName; // unused
(void)originalMessage; // unused
@@ -128,7 +128,7 @@ void rebuildWhisperHighlights(Settings &settings,
if (!args.isReceivedWhisper)
{
return boost::none;
return std::nullopt;
}
return HighlightResult{
@@ -151,7 +151,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
auto highlightAlert = settings.enableThreadHighlightTaskbar.getValue();
auto highlightSoundUrlValue =
settings.threadHighlightSoundUrl.getValue();
boost::optional<QUrl> highlightSoundUrl;
std::optional<QUrl> highlightSoundUrl;
if (!highlightSoundUrlValue.isEmpty())
{
highlightSoundUrl = highlightSoundUrlValue;
@@ -162,7 +162,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
[=](const auto & /*args*/, const auto & /*badges*/,
const auto & /*senderName*/, const auto & /*originalMessage*/,
const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
if (flags.has(MessageFlag::SubscribedThread) && !self)
{
return HighlightResult{
@@ -175,7 +175,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
};
}
return boost::none;
return std::nullopt;
}});
}
}
@@ -219,7 +219,7 @@ void rebuildUserHighlights(Settings &settings,
[showInMentions](
const auto &args, const auto &badges, const auto &senderName,
const auto &originalMessage, const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
(void)args; //unused
(void)badges; //unused
(void)senderName; //unused
@@ -228,7 +228,7 @@ void rebuildUserHighlights(Settings &settings,
if (!self)
{
return boost::none;
return std::nullopt;
}
// Highlight color is provided by the ColorProvider and will be updated accordingly
@@ -246,7 +246,7 @@ void rebuildUserHighlights(Settings &settings,
[highlight](const auto &args, const auto &badges,
const auto &senderName, const auto &originalMessage,
const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
(void)args; // unused
(void)badges; // unused
(void)originalMessage; // unused
@@ -255,10 +255,10 @@ void rebuildUserHighlights(Settings &settings,
if (!highlight.isMatch(senderName))
{
return boost::none;
return std::nullopt;
}
boost::optional<QUrl> highlightSoundUrl;
std::optional<QUrl> highlightSoundUrl;
if (highlight.hasCustomSound())
{
highlightSoundUrl = highlight.getSoundUrl();
@@ -286,7 +286,7 @@ void rebuildBadgeHighlights(Settings &settings,
[highlight](const auto &args, const auto &badges,
const auto &senderName, const auto &originalMessage,
const auto &flags,
const auto self) -> boost::optional<HighlightResult> {
const auto self) -> std::optional<HighlightResult> {
(void)args; // unused
(void)senderName; // unused
(void)originalMessage; // unused
@@ -297,7 +297,7 @@ void rebuildBadgeHighlights(Settings &settings,
{
if (highlight.isMatch(badge))
{
boost::optional<QUrl> highlightSoundUrl;
std::optional<QUrl> highlightSoundUrl;
if (highlight.hasCustomSound())
{
highlightSoundUrl = highlight.getSoundUrl();
@@ -313,7 +313,7 @@ void rebuildBadgeHighlights(Settings &settings,
}
}
return boost::none;
return std::nullopt;
}});
}
}
@@ -323,7 +323,7 @@ void rebuildBadgeHighlights(Settings &settings,
namespace chatterino {
HighlightResult::HighlightResult(bool _alert, bool _playSound,
boost::optional<QUrl> _customSoundUrl,
std::optional<QUrl> _customSoundUrl,
std::shared_ptr<QColor> _color,
bool _showInMentions)
: alert(_alert)
@@ -337,7 +337,7 @@ HighlightResult::HighlightResult(bool _alert, bool _playSound,
HighlightResult HighlightResult::emptyResult()
{
return {
false, false, boost::none, nullptr, false,
false, false, std::nullopt, nullptr, false,
};
}
@@ -395,7 +395,7 @@ std::ostream &operator<<(std::ostream &os, const HighlightResult &result)
os << "Alert: " << (result.alert ? "Yes" : "No") << ", "
<< "Play sound: " << (result.playSound ? "Yes" : "No") << " ("
<< (result.customSoundUrl
? result.customSoundUrl.get().toString().toStdString()
? result.customSoundUrl->toString().toStdString()
: "")
<< ")"
<< ", "
@@ -4,7 +4,6 @@
#include "common/Singleton.hpp"
#include "common/UniqueAccess.hpp"
#include <boost/optional.hpp>
#include <pajlada/settings.hpp>
#include <pajlada/settings/settinglistener.hpp>
#include <QColor>
@@ -12,6 +11,7 @@
#include <functional>
#include <memory>
#include <optional>
#include <utility>
namespace chatterino {
@@ -23,7 +23,7 @@ using MessageFlags = FlagsEnum<MessageFlag>;
struct HighlightResult {
HighlightResult(bool _alert, bool _playSound,
boost::optional<QUrl> _customSoundUrl,
std::optional<QUrl> _customSoundUrl,
std::shared_ptr<QColor> _color, bool _showInMentions);
/**
@@ -46,7 +46,7 @@ struct HighlightResult {
*
* May only be set if playSound is true
**/
boost::optional<QUrl> customSoundUrl{};
std::optional<QUrl> customSoundUrl{};
/**
* @brief set if highlight should set a background color
@@ -76,7 +76,7 @@ struct HighlightResult {
};
struct HighlightCheck {
using Checker = std::function<boost::optional<HighlightResult>(
using Checker = std::function<std::optional<HighlightResult>(
const MessageParseArgs &args, const std::vector<Badge> &badges,
const QString &senderName, const QString &originalMessage,
const MessageFlags &messageFlags, bool self)>;
+1 -1
View File
@@ -127,7 +127,7 @@ int HotkeyController::replaceHotkey(QString oldName,
return this->hotkeys_.append(newHotkey);
}
boost::optional<HotkeyCategory> HotkeyController::hotkeyCategoryFromName(
std::optional<HotkeyCategory> HotkeyController::hotkeyCategoryFromName(
QString categoryName)
{
for (const auto &[category, data] : this->categories())
+1 -3
View File
@@ -4,7 +4,6 @@
#include "common/Singleton.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
@@ -52,8 +51,7 @@ public:
* @returns the new index in the SignalVector
**/
int replaceHotkey(QString oldName, std::shared_ptr<Hotkey> newHotkey);
boost::optional<HotkeyCategory> hotkeyCategoryFromName(
QString categoryName);
std::optional<HotkeyCategory> hotkeyCategoryFromName(QString categoryName);
/**
* @brief checks if the hotkey is duplicate
+3 -2
View File
@@ -3,9 +3,10 @@
#include "controllers/hotkeys/ActionNames.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp"
#include <boost/optional/optional.hpp>
#include <QStringList>
#include <optional>
namespace chatterino {
std::vector<QString> parseHotkeyArguments(QString argumentString)
@@ -31,7 +32,7 @@ std::vector<QString> parseHotkeyArguments(QString argumentString)
return arguments;
}
boost::optional<ActionDefinition> findHotkeyActionDefinition(
std::optional<ActionDefinition> findHotkeyActionDefinition(
HotkeyCategory category, const QString &action)
{
auto allActions = actionNames.find(category);
+2 -2
View File
@@ -2,15 +2,15 @@
#include "controllers/hotkeys/ActionNames.hpp"
#include <boost/optional/optional.hpp>
#include <QString>
#include <optional>
#include <vector>
namespace chatterino {
std::vector<QString> parseHotkeyArguments(QString argumentString);
boost::optional<ActionDefinition> findHotkeyActionDefinition(
std::optional<ActionDefinition> findHotkeyActionDefinition(
HotkeyCategory category, const QString &action);
} // namespace chatterino
@@ -136,7 +136,7 @@ bool ModerationAction::isImage() const
return bool(this->image_);
}
const boost::optional<ImagePtr> &ModerationAction::getImage() const
const std::optional<ImagePtr> &ModerationAction::getImage() const
{
assertInGuiThread();
@@ -2,11 +2,11 @@
#include "util/RapidjsonHelpers.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp>
#include <QString>
#include <memory>
#include <optional>
namespace chatterino {
@@ -21,13 +21,13 @@ public:
bool operator==(const ModerationAction &other) const;
bool isImage() const;
const boost::optional<ImagePtr> &getImage() const;
const std::optional<ImagePtr> &getImage() const;
const QString &getLine1() const;
const QString &getLine2() const;
const QString &getAction() const;
private:
mutable boost::optional<ImagePtr> image_;
mutable std::optional<ImagePtr> image_;
QString line1_;
QString line2_;
QString action_;
+5 -5
View File
@@ -3,12 +3,12 @@
#include "util/RapidjsonHelpers.hpp"
#include "util/RapidJsonSerializeQString.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp>
#include <QRegularExpression>
#include <QString>
#include <memory>
#include <optional>
namespace chatterino {
@@ -59,18 +59,18 @@ public:
return this->isCaseSensitive_;
}
[[nodiscard]] boost::optional<QString> match(
[[nodiscard]] std::optional<QString> match(
const QString &usernameText) const
{
if (this->isRegex())
{
if (!this->regex_.isValid())
{
return boost::none;
return std::nullopt;
}
if (this->name().isEmpty())
{
return boost::none;
return std::nullopt;
}
auto workingCopy = usernameText;
@@ -90,7 +90,7 @@ public:
}
}
return boost::none;
return std::nullopt;
}
private:
+3 -2
View File
@@ -3,11 +3,12 @@
#include "util/RapidjsonHelpers.hpp"
#include "util/RapidJsonSerializeQString.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp>
#include <QColor>
#include <QString>
#include <optional>
namespace chatterino {
// UserData defines a set of data that is defined for a unique user
@@ -15,7 +16,7 @@ namespace chatterino {
// or a user note that should be displayed with the user
// Replacement fields should be optional, where none denotes that the field should not be updated for the user
struct UserData {
boost::optional<QColor> color{boost::none};
std::optional<QColor> color{std::nullopt};
// TODO: User note?
};
@@ -2,6 +2,7 @@
#include "singletons/Paths.hpp"
#include "util/CombinePath.hpp"
#include "util/Helpers.hpp"
namespace {
@@ -42,15 +43,14 @@ void UserDataController::save()
this->sm->save();
}
boost::optional<UserData> UserDataController::getUser(
const QString &userID) const
std::optional<UserData> UserDataController::getUser(const QString &userID) const
{
std::shared_lock lock(this->usersMutex);
auto it = this->users.find(userID);
if (it == this->users.end())
{
return boost::none;
return std::nullopt;
}
return it->second;
@@ -67,8 +67,8 @@ void UserDataController::setUserColor(const QString &userID,
{
auto c = this->getUsers();
auto it = c.find(userID);
boost::optional<QColor> finalColor =
boost::make_optional(!colorString.isEmpty(), QColor(colorString));
std::optional<QColor> finalColor =
makeConditionedOptional(!colorString.isEmpty(), QColor(colorString));
if (it == c.end())
{
if (!finalColor)
@@ -7,11 +7,11 @@
#include "util/RapidJsonSerializeQString.hpp"
#include "util/serialize/Container.hpp"
#include <boost/optional.hpp>
#include <pajlada/settings.hpp>
#include <QColor>
#include <QString>
#include <optional>
#include <shared_mutex>
#include <unordered_map>
@@ -22,7 +22,7 @@ class IUserDataController
public:
virtual ~IUserDataController() = default;
virtual boost::optional<UserData> getUser(const QString &userID) const = 0;
virtual std::optional<UserData> getUser(const QString &userID) const = 0;
virtual void setUserColor(const QString &userID,
const QString &colorString) = 0;
@@ -35,7 +35,7 @@ public:
// Get extra data about a user
// If the user does not have any extra data, return none
boost::optional<UserData> getUser(const QString &userID) const override;
std::optional<UserData> getUser(const QString &userID) const override;
// Update or insert extra data for the user's color override
void setUserColor(const QString &userID,