simple_enum

expected_ec and make_unexpected_ec

Overview

Usage

Ensure inclusion .

#include <simple_enum/generic_error_category.hpp>

expected_ec Type Alias

template<typename T>
using expected_ec = std::expected<T, std::error_code>;

unexpected_ec Type Alias

using unexpected_ec = std::unexpected<std::error_code>;

make_unexpected_ec Function

template<concepts::error_enum ErrorEnum>
[[nodiscard]] auto make_unexpected_ec(ErrorEnum e) -> unexpected_ec;

Example Usage

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
}