这个用std::expected<>重构完了,没啥代码量。
原来返回的三值(成功、失败、没变)给改成二值。
struct HttpSuccessTag {};
struct HttpErrorTag {};
using HttpResponsePayload = StrongTypedef<std::string, HttpSuccessTag>;
using HttpErrorMessage = StrongTypedef<std::string, HttpErrorTag>;
std::expected<HttpResponsePayload, HttpErrorMessage> HttpPostNew() {}
std::string HttpPost() {
const auto result = HttpPostNew();
if (result)
return result.value().get();
static constexpr auto errorPrefix = "###Error### ";
return errorPrefix + result.error().get();
}
【 在 llwwwww 的大作中提到: 】
: 你先搞个新的,然后新的调用代码调你的新的。搞一阵以后新的架构就清晰了。老的可动,也可不动。
: 老的也是久经考验的了
:
--
修改:z16166 FROM 111.199.147.*
FROM 111.199.147.*