modify something

This commit is contained in:
CupWater
2026-08-17 21:01:29 +08:00
parent 3274bf9393
commit 4fc7ef37c2
12 changed files with 133 additions and 47 deletions
+11 -11
View File
@@ -4,37 +4,37 @@
#include <optional>
#include <functional>
namespace flog {
namespace flog
{
template <typename T>
class PushResult {
class PushResult
{
public:
_NODISCARD static PushResult success() noexcept { return PushResult(); }
_NODISCARD static PushResult failWithValue(T value) noexcept {
_NODISCARD static PushResult failWithValue(T value) noexcept
{
return PushResult(std::move(std::optional<T>(std::move(value))));
}
_NODISCARD bool isSuccessful() const noexcept { return !m_value.has_value(); }
_NODISCARD bool isFail() const noexcept { return m_value.has_value(); }
void getValueIfFail(const std::function<void(const T& value)> func) const {
void getValueIfFail(const std::function<void(const T& value)> func) const
{
if (isFail()) {
func(m_value.value());
}
}
_NODISCARD T getValue() const {
return m_value.value();
}
_NODISCARD T getValue() const { return m_value.value(); }
PushResult(const PushResult &other) noexcept {
m_value = other.m_value;
}
PushResult(const PushResult &other) noexcept { m_value = other.m_value; }
private:
PushResult() noexcept = default;
explicit PushResult(std::optional<T> value) noexcept : m_value(std::move(value)) {}
std::optional<T> m_value = std::nullopt;
const std::optional<T> m_value = std::nullopt;
};
}