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

Conversation

pajlada
Copy link
Member

@pajlada pajlada commented Oct 8, 2023

Description

The commits are split up into two parts:

  1. The actual replacing of boost::optional with std::optional
  2. The small refactors I've done around the code as the replacing took place - there weren't many things I changed, mostly just

Copy link
Member Author

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Looks good to me

image

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

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

@@ -127,7 +127,7 @@ int HotkeyController::replaceHotkey(QString oldName,
return this->hotkeys_.append(newHotkey);
}

boost::optional<HotkeyCategory> HotkeyController::hotkeyCategoryFromName(
std::optional<HotkeyCategory> HotkeyController::hotkeyCategoryFromName(
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'hotkeyCategoryFromName' can be made const [readability-make-member-function-const]

src/controllers/hotkeys/HotkeyController.hpp:53:

-     std::optional<HotkeyCategory> hotkeyCategoryFromName(QString categoryName);
+     std::optional<HotkeyCategory> hotkeyCategoryFromName(QString categoryName) const;

src/controllers/hotkeys/HotkeyController.cpp:130:

-     QString categoryName)
+     QString categoryName) const

@@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable 'finalColor' of type 'std::optional' can be declared 'const' [misc-const-correctness]

Suggested change
std::optional<QColor> finalColor =
std::optional<QColor> const finalColor =

src/messages/SharedMessageBuilder.cpp Show resolved Hide resolved
@@ -727,14 +727,14 @@ void PubSub::registerNonce(QString nonce, NonceInfo info)
this->nonces_[nonce] = std::move(info);
}

boost::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce)
std::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'nonce' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
std::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce)
std::optional<PubSub::NonceInfo> PubSub::findNonceInfo(const QString& nonce)

src/providers/twitch/PubSubManager.hpp:190:

-     std::optional<NonceInfo> findNonceInfo(QString nonce);
+     std::optional<NonceInfo> findNonceInfo(const QString& nonce);

@@ -955,13 +955,13 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
return;
}

boost::optional<QString> oldUserID = boost::make_optional(
std::optional<QString> oldUserID = makeConditionedOptional(
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable 'oldUserID' of type 'std::optional' can be declared 'const' [misc-const-correctness]

Suggested change
std::optional<QString> oldUserID = makeConditionedOptional(
std::optional<QString> const oldUserID = makeConditionedOptional(

boost::make_optional(!this->seventvEmoteSetID_.isEmpty() &&
this->seventvEmoteSetID_ != newEmoteSetID,
this->seventvEmoteSetID_);
std::optional<QString> oldEmoteSetID =
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable 'oldEmoteSetID' of type 'std::optional' can be declared 'const' [misc-const-correctness]

Suggested change
std::optional<QString> oldEmoteSetID =
std::optional<QString> const oldEmoteSetID =

return Success;
}

return Failure;
}

boost::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
const Badge &badge)
std::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(const Badge &badge)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'getTwitchBadge' can be made const [readability-make-member-function-const]

Suggested change
std::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(const Badge &badge)
std::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(const Badge &badge) const

src/providers/twitch/TwitchMessageBuilder.hpp:110:

-     std::optional<EmotePtr> getTwitchBadge(const Badge &badge);
+     std::optional<EmotePtr> getTwitchBadge(const Badge &badge) const;

src/util/NuulsUploader.cpp Show resolved Hide resolved
@@ -308,15 +307,17 @@ void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs)
else
{
/// If the new time point is newer then we override.
if (it->second && it->second.get() < timePoint)
if (it->second && it->second.value() < timePoint)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unchecked access to optional value [bugprone-unchecked-optional-access]

            if (it->second && it->second.value() < timePoint)
                              ^

@pajlada pajlada enabled auto-merge (squash) October 8, 2023 14:35
@pajlada pajlada merged commit fec4588 into master Oct 8, 2023
15 checks passed
@pajlada pajlada deleted the chore/remove-use-of-boost-optional branch October 8, 2023 16:50
Felanbird added a commit to Felanbird/chatterino2 that referenced this pull request Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant