Replace boost::optional with std::optional (#4877)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QStringRef>
|
||||
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -155,4 +156,28 @@ std::vector<T> splitListIntoBatches(const T &list, int batchSize = 100)
|
||||
|
||||
bool compareEmoteStrings(const QString &a, const QString &b);
|
||||
|
||||
template <class T>
|
||||
constexpr std::optional<T> makeConditionedOptional(bool condition,
|
||||
const T &value)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
constexpr std::optional<std::decay_t<T>> makeConditionedOptional(bool condition,
|
||||
T &&value)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
return std::optional<std::decay_t<T>>(std::forward<T>(value));
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+11
-11
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
boost::optional<QByteArray> convertToPng(QImage image)
|
||||
std::optional<QByteArray> convertToPng(const QImage &image)
|
||||
{
|
||||
QByteArray imageData;
|
||||
QBuffer buf(&imageData);
|
||||
@@ -31,16 +31,16 @@ boost::optional<QByteArray> convertToPng(QImage image)
|
||||
bool success = image.save(&buf, "png");
|
||||
if (success)
|
||||
{
|
||||
return boost::optional<QByteArray>(imageData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return boost::optional<QByteArray>(boost::none);
|
||||
return imageData;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// These variables are only used from the main thread.
|
||||
static auto uploadMutex = QMutex();
|
||||
static std::queue<RawImageData> uploadQueue;
|
||||
@@ -271,10 +271,10 @@ void upload(const QMimeData *source, ChannelPtr channel,
|
||||
return;
|
||||
}
|
||||
|
||||
boost::optional<QByteArray> imageData = convertToPng(img);
|
||||
auto imageData = convertToPng(img);
|
||||
if (imageData)
|
||||
{
|
||||
RawImageData data = {imageData.get(), "png", localPath};
|
||||
RawImageData data = {*imageData, "png", localPath};
|
||||
uploadQueue.push(data);
|
||||
}
|
||||
else
|
||||
@@ -339,11 +339,11 @@ void upload(const QMimeData *source, ChannelPtr channel,
|
||||
|
||||
else
|
||||
{ // not PNG, try loading it into QImage and save it to a PNG.
|
||||
QImage image = qvariant_cast<QImage>(source->imageData());
|
||||
boost::optional<QByteArray> imageData = convertToPng(image);
|
||||
auto image = qvariant_cast<QImage>(source->imageData());
|
||||
auto imageData = convertToPng(image);
|
||||
if (imageData)
|
||||
{
|
||||
uploadImageToNuuls({imageData.get(), "png", ""}, channel,
|
||||
uploadImageToNuuls({*imageData, "png", ""}, channel,
|
||||
outputTextEdit);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -22,7 +22,7 @@ using GetDpiForMonitor_ = HRESULT(CALLBACK *)(HMONITOR, MONITOR_DPI_TYPE,
|
||||
UINT *, UINT *);
|
||||
|
||||
// TODO: This should be changed to `GetDpiForWindow`.
|
||||
boost::optional<UINT> getWindowDpi(HWND hwnd)
|
||||
std::optional<UINT> getWindowDpi(HWND hwnd)
|
||||
{
|
||||
static HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
|
||||
if (shcore != nullptr)
|
||||
@@ -41,7 +41,7 @@ boost::optional<UINT> getWindowDpi(HWND hwnd)
|
||||
}
|
||||
}
|
||||
|
||||
return boost::none;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void flushClipboard()
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
#ifdef USEWINSDK
|
||||
|
||||
# include <boost/optional.hpp>
|
||||
# include <QString>
|
||||
# include <Windows.h>
|
||||
|
||||
# include <optional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
enum class AssociationQueryType { Protocol, FileExtension };
|
||||
|
||||
boost::optional<UINT> getWindowDpi(HWND hwnd);
|
||||
std::optional<UINT> getWindowDpi(HWND hwnd);
|
||||
void flushClipboard();
|
||||
|
||||
bool isRegisteredForStartup();
|
||||
|
||||
Reference in New Issue
Block a user