expected_ec and make_unexpected_ecexpected_ec is a template alias simplifying usage of std::expected with std::error_code for error handling.make_unexpected_ec is a utility function creating an unexpected object initialized with a std::error_code generated from an enumeration representing error conditions.Ensure inclusion .
#include <simple_enum/generic_error_category.hpp>
expected_ec Type Aliastemplate<typename T>
using expected_ec = std::expected<T, std::error_code>;
T or an error of type std::error_code.unexpected_ec Type Aliasusing unexpected_ec = std::unexpected<std::error_code>;
unexpected type carrying a std::error_code.make_unexpected_ec Functiontemplate<concepts::error_enum ErrorEnum>
[[nodiscard]] auto make_unexpected_ec(ErrorEnum e) -> unexpected_ec;
unexpected_ec object from an enumeration value e representing an error. This leverages make_error_code to convert enumeration to std::error_code.enum class error_code { none, error1, error2, error3 };
// Using expected_ec and make_unexpected_ec for error handling
auto func() -> expected_ec<int> {
if(/* error condition */) {
return make_unexpected_ec(error_code::error1);
}
return 42; // Success path returns a value
}