From ec1a0bc44b1804a84102049dbe8881db8673ae30 Mon Sep 17 00:00:00 2001 From: "Vladimir (Alkenso)" Date: Sat, 3 Aug 2019 03:07:33 +0300 Subject: [PATCH] Update README.md --- README.md | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 0d16559..eb129ca 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,14 @@ asenum combines Enum and Variant: it allows to create lighweight wrapper around ## Example ``` -// Header contains extended usage case +// For more examples see tests #include #include #include #include +// ===== DECLARATION ===== enum class ErrorCode { Unknown, @@ -29,41 +30,36 @@ enum class ErrorCode }; // Associate enum 'ErrorCode' with AsEnum 'AnyError' -ASENUM_DECLARE(AnyError, ErrorCode) -{ - ASENUM_DEFINE_STRUCTORS(); - - ASENUM_CASE(Unknown, std::string); - ASENUM_CASE_VOID(Success); - ASENUM_CASE(Timeout, std::chrono::seconds); -}; +using AnyError = asenum::AsEnum< +asenum::Case11, +asenum::Case11, +asenum::Case11 +>; -//===== USAGE ===== +// ===== USAGE ===== void LogSetting(const AnyError& event) { - switch (event.type()) - { - case ErrorCode::Unknown: - std::cout << "Unknown error: " << event.asUnknown() << "\n"; - break; - case ErrorCode::Success: - std::cout << "Success\n"; - break; - case ErrorCode::Timeout: - std::cout << "Timed out after: " << event.asTimeout().count() << "\n"; - break; - default: - std::cout << "Default\n"; - break; - } + event.doSwitch() + .ifCase([] (const std::string& value) { + std::cout << "Unknown error: " << value << "\n"; + }) + .ifCase([] { + std::cout << "Success\n"; + }) + .ifCase([] (const std::chrono::seconds& value) { + std::cout << "Timed out after: " << value.count() << "\n"; + }) + .ifDefault([] { + std::cout << "Default\n"; + }); } int main() { // ===== CREATION ===== - LogSetting(AnyError::createUnknown("test.api.com")); - LogSetting(AnyError::createSuccess()); - LogSetting(AnyError::createTimeout(std::chrono::seconds(1))); + LogSetting(AnyError::create("test.api.com")); + LogSetting(AnyError::create()); + LogSetting(AnyError::create(std::chrono::seconds(1))); return 0; }