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
@@ -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)>;