SHA256
finish log_manager.cpp
This commit is contained in:
@@ -2,22 +2,39 @@
|
||||
#define FEATHERLOG_PUSH_RESULT_HPP
|
||||
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
|
||||
namespace flog {
|
||||
template <typename T>
|
||||
class PushResult {
|
||||
public:
|
||||
static PushResult getVoid() {
|
||||
return PushResult(3);
|
||||
_NODISCARD static PushResult success() noexcept { return PushResult(); }
|
||||
_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 {
|
||||
if (isFail()) {
|
||||
func(m_value.value());
|
||||
}
|
||||
}
|
||||
|
||||
_NODISCARD T getValue() const {
|
||||
return m_value.value();
|
||||
}
|
||||
|
||||
PushResult(const PushResult &other) noexcept {
|
||||
m_value = other.m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
explicit PushResult(std::optional<T> value) : m_value(value) {
|
||||
std::optional<T> bad;
|
||||
std::map<int, std::optional<T>> mp;
|
||||
}
|
||||
PushResult() noexcept = default;
|
||||
explicit PushResult(std::optional<T> value) noexcept : m_value(std::move(value)) {}
|
||||
|
||||
std::optional<T> m_value;
|
||||
std::optional<T> m_value = std::nullopt;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user