Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 15 commits into from
Oct 8, 2023
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Dev: Add a compile-time flag `CHATTERINO_UPDATER` which can be turned off to disable update checks. (#4854)
- Dev: Add a compile-time flag `USE_SYSTEM_MINIAUDIO` which can be turned on to use the system miniaudio. (#4867)
- Dev: Update vcpkg to use Qt6. (#4872)
- Dev: Replace `boost::optional` with `std::optional`. (#4877)

## 2.4.6

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int compare(const QString &a, const QString &b);
* link
* ^^^ No need to repeat the obvious.
*/
boost::optional<QRegularExpressionMatch> matchLink(const QString &text);
std::optional<QRegularExpressionMatch> matchLink(const QString &text);
```

# Code
Expand Down
8 changes: 4 additions & 4 deletions mocks/include/mocks/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class Helix : public IHelix
// contains a comma
MOCK_METHOD(void, updateFollowerMode,
(QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration,
std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback,
(FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback)),
Expand All @@ -279,7 +279,7 @@ class Helix : public IHelix
// contains a comma
MOCK_METHOD(void, updateNonModeratorChatDelay,
(QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration,
std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback,
(FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback)),
Expand All @@ -289,7 +289,7 @@ class Helix : public IHelix
// contains a comma
MOCK_METHOD(void, updateSlowMode,
(QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime,
std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback,
(FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback)),
Expand Down Expand Up @@ -321,7 +321,7 @@ class Helix : public IHelix
// contains a comma
MOCK_METHOD(void, banUser,
(QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason,
std::optional<int> duration, QString reason,
ResultCallback<> successCallback,
(FailureCallback<HelixBanUserError, QString> failureCallback)),
(override)); // /timeout, /ban
Expand Down
4 changes: 2 additions & 2 deletions mocks/include/mocks/UserData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class UserDataController : public IUserDataController

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'userID' is unused [misc-unused-parameters]

Suggested change
std::optional<UserData> getUser(const QString &userID) const override
std::optional<UserData> getUser(const QString & /*userID*/) const override

{
return boost::none;
return std::nullopt;
}

// Update or insert extra data for the user's color override
Expand Down
2 changes: 1 addition & 1 deletion src/PrecompiledHeader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# include <boost/circular_buffer.hpp>
# include <boost/current_function.hpp>
# include <boost/foreach.hpp>
# include <boost/optional.hpp>
# include <boost/signals2.hpp>
# include <IrcCommand>
# include <IrcConnection>
Expand Down Expand Up @@ -117,6 +116,7 @@
# include <map>
# include <memory>
# include <mutex>
# include <optional>
# include <random>
# include <set>
# include <string>
Expand Down
7 changes: 4 additions & 3 deletions src/common/Args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#include "common/WindowDescriptors.hpp"

#include <boost/optional.hpp>
#include <QApplication>

#include <optional>

namespace chatterino {

/// Command line arguments passed to Chatterino.
Expand All @@ -18,12 +19,12 @@ class Args
bool shouldRunBrowserExtensionHost{};
// Shows a single chat. Used on windows to embed in another application.
bool isFramelessEmbed{};
boost::optional<unsigned long long> parentWindowId{};
std::optional<unsigned long long> parentWindowId{};

// Not settings directly
bool dontSaveSettings{};
bool dontLoadMainWindow{};
boost::optional<WindowLayout> customChannelLayout;
std::optional<WindowLayout> customChannelLayout;
bool verbose{};

private:
Expand Down
2 changes: 1 addition & 1 deletion src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
}

void Channel::addMessage(MessagePtr message,
boost::optional<MessageFlags> overridingFlags)
std::optional<MessageFlags> overridingFlags)
{
auto app = getApp();
MessagePtr deleted;
Expand Down
9 changes: 4 additions & 5 deletions src/common/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include "controllers/completion/TabCompletionModel.hpp"
#include "messages/LimitedQueue.hpp"

#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp>
#include <QDate>
#include <QString>
#include <QTimer>

#include <memory>
#include <optional>

namespace chatterino {

Expand Down Expand Up @@ -52,7 +52,7 @@ class Channel : public std::enable_shared_from_this<Channel>
pajlada::Signals::Signal<const QString &, const QString &, const QString &,
bool &>
sendReplySignal;
pajlada::Signals::Signal<MessagePtr &, boost::optional<MessageFlags>>
pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
messageAppended;
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced;
Expand All @@ -75,9 +75,8 @@ class Channel : public std::enable_shared_from_this<Channel>
// overridingFlags can be filled in with flags that should be used instead
// of the message's flags. This is useful in case a flag is specific to a
// type of split
void addMessage(
MessagePtr message,
boost::optional<MessageFlags> overridingFlags = boost::none);
void addMessage(MessagePtr message,
std::optional<MessageFlags> overridingFlags = std::nullopt);
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);

/// Inserts the given messages in order by Message::serverReceivedTime.
Expand Down
2 changes: 1 addition & 1 deletion src/common/Common.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <boost/optional.hpp>
#include <boost/preprocessor.hpp>
#include <QString>
#include <QWidget>

#include <memory>
#include <optional>
#include <string>

namespace chatterino {
Expand Down
4 changes: 2 additions & 2 deletions src/common/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ namespace {
return defaultValue;
}

boost::optional<QString> readOptionalStringEnv(const char *envName)
std::optional<QString> readOptionalStringEnv(const char *envName)
{
auto envString = std::getenv(envName);
if (envString != nullptr)
{
return QString(envString);
}

return boost::none;
return std::nullopt;
}

uint16_t readPortEnv(const char *envName, uint16_t defaultValue)
Expand Down
5 changes: 3 additions & 2 deletions src/common/Env.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <boost/optional.hpp>
#include <QString>

#include <optional>

namespace chatterino {

class Env
Expand All @@ -17,7 +18,7 @@ class Env
const QString twitchServerHost;
const uint16_t twitchServerPort;
const bool twitchServerSecure;
const boost::optional<QString> proxyUrl;
const std::optional<QString> proxyUrl;
};

} // namespace chatterino
15 changes: 9 additions & 6 deletions src/common/SignalVectorModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#include "common/SignalVector.hpp"

#include <boost/optional.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QAbstractTableModel>
#include <QMimeData>
#include <QStandardItem>

#include <optional>

namespace chatterino {

template <typename T>
Expand Down Expand Up @@ -127,7 +128,8 @@ class SignalVectorModel : public QAbstractTableModel,

QVariant data(const QModelIndex &index, int role) const override
{
int row = index.row(), column = index.column();
int row = index.row();
int column = index.column();
if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_)
{
Expand All @@ -140,7 +142,8 @@ class SignalVectorModel : public QAbstractTableModel,
bool setData(const QModelIndex &index, const QVariant &value,
int role) override
{
int row = index.row(), column = index.column();
int row = index.row();
int column = index.column();
if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_)
{
Expand All @@ -166,7 +169,7 @@ class SignalVectorModel : public QAbstractTableModel,

assert(this->rows_[row].original);
TVectorItem item = this->getItemFromRow(
this->rows_[row].items, this->rows_[row].original.get());
this->rows_[row].items, this->rows_[row].original.value());
this->vector_->insert(item, vecRow, this);
}

Expand Down Expand Up @@ -262,7 +265,7 @@ class SignalVectorModel : public QAbstractTableModel,

TVectorItem item =
this->getItemFromRow(this->rows_[sourceRow].items,
this->rows_[sourceRow].original.get());
this->rows_[sourceRow].original.value());
this->vector_->removeAt(signalVectorRow);
this->vector_->insert(
item, this->getVectorIndexFromModelIndex(destinationChild));
Expand Down Expand Up @@ -417,7 +420,7 @@ class SignalVectorModel : public QAbstractTableModel,

struct Row {
std::vector<QStandardItem *> items;
boost::optional<TVectorItem> original;
std::optional<TVectorItem> original;
bool isCustomRow;

Row(std::vector<QStandardItem *> _items, bool _isCustomRow = false)
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/commands/builtin/twitch/ChatSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down Expand Up @@ -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 "";
Expand Down
Loading
Loading