C++ 23 -> C++ 20; std::expected -> Expected (#3)

This commit is contained in:
David Chen
2025-12-21 05:07:04 +08:00
committed by GitHub
parent 0f41240eeb
commit 834d5d5964
2 changed files with 16 additions and 13 deletions

View File

@@ -1,6 +1,5 @@
#include <hiredis/hiredis.h>
#include <expected>
#include <format>
#include <iostream>
#include <memory>
@@ -12,6 +11,8 @@
#include <unordered_map>
#include <vector>
#include "expected.h"
struct FieldVal {
std::string field, val;
};
@@ -73,7 +74,7 @@ class RedisClient {
if (ctx_) redisFree(ctx_);
}
std::expected<void, std::string> xadd(const XaddReq& req) noexcept {
Expected<void> xadd(const XaddReq& req) noexcept {
// todo: safe guard against invalid requests
std::stringstream ss;
@@ -84,15 +85,15 @@ class RedisClient {
auto reply = submit_cmd(ss.str());
if (!reply) {
return std::unexpected(ctx_->errstr);
return Unexpected(ctx_->errstr);
} else if (reply->type == REDIS_REPLY_ERROR) {
return std::unexpected(reply->str ? reply->str : "unknown error");
return Unexpected(reply->str ? reply->str : "unknown error");
}
return {};
}
std::expected<XreadRes, std::string> xread(const XreadReq& req) noexcept {
Expected<XreadRes> xread(const XreadReq& req) noexcept {
// todo: safe guard against invalid requests
std::stringstream ss;
@@ -105,14 +106,13 @@ class RedisClient {
auto reply = submit_cmd(ss.str());
if (!reply) {
return std::unexpected(ctx_->errstr);
return Unexpected(ctx_->errstr);
} else if (reply->type == REDIS_REPLY_ERROR) {
return std::unexpected(reply->str ? reply->str : "unknown reply error");
return Unexpected(reply->str ? reply->str : "unknown reply error");
} else if (reply->type == REDIS_REPLY_NIL) {
return {};
} else if (reply->type != REDIS_REPLY_ARRAY) {
return std::unexpected(
std::format("unexpected reply type {}", reply->type));
return Unexpected(std::format("unexpected reply type {}", reply->type));
}
XreadRes res;