1
0

refactor: finish Windows encoding namespace.

- finish Windows encoding namespace.
- add std::expected polyfill for help.
This commit is contained in:
2025-07-14 15:06:33 +08:00
parent fa52d7416f
commit 3605151caf
8 changed files with 425 additions and 56 deletions

View File

@@ -0,0 +1,40 @@
#pragma once
#include <type_traits>
#include <variant>
/**
* @brief A stupid polyfill for std::expected,
*
* For those C++ standard which do not support std::expected,
* we provide this namespace with a pretty bad but at least working std::expected pplyfill.
*
* The polyfill was done by std::variant.
*
* This namespace is used by this project because this framework must support C++ 17.
*/
namespace yycc::patch::expected {
template<typename TValue, typename TError, std::enable_if_t<!std::is_same_v<TValue, TError>, int> = 0>
using Expected = std::variant<TValue, TError>;
template<typename TValue, typename TError>
bool is_value(const Expected<TValue, TError>& exp) {
return exp.index() == 0u;
}
template<typename TValue, typename TError>
bool is_error(const Expected<TValue, TError>& exp) {
return exp.index() == 1u;
}
template<typename TValue, typename TError>
const TValue& get_value(const Expected<TValue, TError>& exp) {
return std::get<0>(exp);
}
template<typename TValue, typename TError>
const TError& get_error(const Expected<TValue, TError>& exp) {
return std::get<1>(exp);
}
}