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
|
||||
|
||||
Reference in New Issue
Block a user