{"id":15047581,"url":"https://github.com/mguludag/expected","last_synced_at":"2026-01-29T05:42:13.436Z","repository":{"id":250738938,"uuid":"835333322","full_name":"mguludag/expected","owner":"mguludag","description":"An extended version of C++23's std::expected\u003cT, E\u003e to use with variadic errors like expected\u003cT, E1, E2, ...\u003e","archived":false,"fork":false,"pushed_at":"2024-08-17T12:00:56.000Z","size":183,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:51:03.226Z","etag":null,"topics":["cpp17","cpp20","cpp23","cpp26","error-handling","expected"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mguludag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-29T16:07:49.000Z","updated_at":"2024-09-30T10:28:08.000Z","dependencies_parsed_at":"2025-02-16T06:32:07.371Z","dependency_job_id":"8ae60d4d-55f5-4e1f-a7cb-513a778d55e5","html_url":"https://github.com/mguludag/expected","commit_stats":null,"previous_names":["mguludag/expected"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fexpected","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fexpected/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fexpected/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguludag%2Fexpected/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mguludag","download_url":"https://codeload.github.com/mguludag/expected/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137997,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp17","cpp20","cpp23","cpp26","error-handling","expected"],"created_at":"2024-09-24T21:00:43.455Z","updated_at":"2026-01-29T05:42:13.408Z","avatar_url":"https://github.com/mguludag.png","language":"C++","readme":"# expected\n\nAn extended version of C++23's `std::expected\u003cT, E\u003e` to handle variadic errors, allowing usage like `expected\u003cT, E1, E2, ...\u003e`.\n\n## Table of Contents\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Example](#basic-example)\n  - [Advanced Example](#advanced-example)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n- Compatible with C++17\n- Supports multiple error types.\n- Enhances standard `std::expected` functionality.\n\n## Installation\nClone the repository:\n```sh\ngit clone https://github.com/mguludag/expected.git\n```\nInclude the `include` directory in your project.\n\n## [Usage (click to demo)](https://godbolt.org/z/jonM4nf3b)\n\n### Basic Example\nHere's a simple example of how to use `expected` with multiple error types:\n```cpp\n#include \u003cmgutility/expected.hpp\u003e\n\nmgutility::expected\u003cint, std::string\u003e divide(int a, int b) {\n    if (b == 0) return mgutility::unexpected{\"Division by zero\"};\n    return a / b;\n}\n\nint main() {\n    auto result = divide(4, 2);\n    if (!result) {\n        // Handle error\n    }\n    // Use result\n}\n```\n\n### Advanced Example\n\n\n#### Using `.and_then` for success and `.or_else` per Error Type and using `.transform`\n* Chain operations that depend on the success of the previous one, and handle specific errors with `or_else`\n* Transform the value inside `expected` if it is present\n```cpp\n#include \u003cmgutility/expected.hpp\u003e\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003csystem_error\u003e\n\nmgutility::expected\u003cint, std::string, std::error_code\u003e divide(int a, int b) {\n    if (b == 0) return mgutility::unexpected\u003cstd::string\u003e(\"Division by zero\");\n    if (a \u003c 0) return mgutility::unexpected{std::make_error_code(std::errc::invalid_argument)};\n    return a / b;\n}\n\nmgutility::expected\u003cint, std::string, std::error_code\u003e addOne(int x) {\n    return x + 1;\n}\n\nint main() {\n    auto result = divide(10, 2)\n        .and_then(addOne)\n        .transform([](int x) { return x * 2; })\n        .or_else([](const std::string\u0026 err) -\u003e mgutility::expected\u003cint, std::string, std::error_code\u003e {\n            std::cerr \u003c\u003c \"String error: \" \u003c\u003c err \u003c\u003c std::endl;\n            return mgutility::unexpected\u003cstd::string\u003e(\"Handled string error\");\n        })\n        .or_else([](const std::error_code\u0026 err) -\u003e mgutility::expected\u003cint, std::string\u003e {\n            std::cerr \u003c\u003c \"Error code: \" \u003c\u003c err.message() \u003c\u003c std::endl;\n            return mgutility::unexpected(err.message());\n        });\n\n    if (result) {\n        std::cout \u003c\u003c \"Result: \" \u003c\u003c *result \u003c\u003c std::endl;\n    } else {\n      // use result.error\u003cstd::string\u003e() or result.error()\n      std::cerr \u003c\u003c \"Error: \" \u003c\u003c result.error() \u003c\u003c std::endl;\n    }\n}\n\n```\n\n## Contributing\nContributions are welcome! Please open issues or pull requests.\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\nThis `README.md` provides a complete guide with basic and advanced usage examples, including multiple error types and chained handling using monadic operations.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmguludag%2Fexpected","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmguludag%2Fexpected","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmguludag%2Fexpected/lists"}