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
+7 -7
View File
@@ -1,11 +1,12 @@
#pragma once
#include <boost/optional.hpp>
#include <magic_enum.hpp>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <optional>
namespace chatterino {
struct PubSubMessage {
@@ -27,16 +28,16 @@ struct PubSubMessage {
PubSubMessage(QJsonObject _object);
template <class InnerClass>
boost::optional<InnerClass> toInner();
std::optional<InnerClass> toInner();
};
template <class InnerClass>
boost::optional<InnerClass> PubSubMessage::toInner()
std::optional<InnerClass> PubSubMessage::toInner()
{
auto dataValue = this->object.value("data");
if (!dataValue.isObject())
{
return boost::none;
return std::nullopt;
}
auto data = dataValue.toObject();
@@ -44,14 +45,13 @@ boost::optional<InnerClass> PubSubMessage::toInner()
return InnerClass{this->nonce, data};
}
static boost::optional<PubSubMessage> parsePubSubBaseMessage(
const QString &blob)
static std::optional<PubSubMessage> parsePubSubBaseMessage(const QString &blob)
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull())
{
return boost::none;
return std::nullopt;
}
return PubSubMessage(jsonDoc.object());
@@ -2,11 +2,12 @@
#include "common/QLogging.hpp"
#include <boost/optional.hpp>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <optional>
namespace chatterino {
struct PubSubMessageMessage {
@@ -42,15 +43,15 @@ struct PubSubMessageMessage {
}
template <class InnerClass>
boost::optional<InnerClass> toInner() const;
std::optional<InnerClass> toInner() const;
};
template <class InnerClass>
boost::optional<InnerClass> PubSubMessageMessage::toInner() const
std::optional<InnerClass> PubSubMessageMessage::toInner() const
{
if (this->messageObject.empty())
{
return boost::none;
return std::nullopt;
}
return InnerClass{this->messageObject};