{"id":18534899,"url":"https://github.com/gregorykogan/result","last_synced_at":"2025-05-15T00:15:13.843Z","repository":{"id":213430694,"uuid":"733002985","full_name":"GregoryKogan/result","owner":"GregoryKogan","description":"result is a C++ library that provides a Result type, which can be used to return and propagate errors. It's inspired by Rust's Result type.","archived":false,"fork":false,"pushed_at":"2024-02-19T11:07:56.000Z","size":332,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-26T03:12:01.969Z","etag":null,"topics":["auto-documentation","cpp","doxygen","doxygen-documentation","doxygen-theme","error-handling","functional-programming","modern-cpp","result-type"],"latest_commit_sha":null,"homepage":"https://gregorykogan.github.io/result/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GregoryKogan.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":"2023-12-18T10:48:34.000Z","updated_at":"2024-05-20T19:41:19.000Z","dependencies_parsed_at":"2024-01-15T09:06:02.913Z","dependency_job_id":"d4133ba9-9868-4aad-8fb1-c51388aeed54","html_url":"https://github.com/GregoryKogan/result","commit_stats":{"total_commits":53,"total_committers":1,"mean_commits":53.0,"dds":0.0,"last_synced_commit":"be9335854326c549811d71e0ab481b979d4890aa"},"previous_names":["gregorykogan/result-cpp","gregorykogan/result"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryKogan%2Fresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryKogan%2Fresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryKogan%2Fresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GregoryKogan%2Fresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GregoryKogan","download_url":"https://codeload.github.com/GregoryKogan/result/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239248801,"owners_count":19607097,"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":["auto-documentation","cpp","doxygen","doxygen-documentation","doxygen-theme","error-handling","functional-programming","modern-cpp","result-type"],"created_at":"2024-11-06T19:17:48.074Z","updated_at":"2025-02-17T07:20:04.292Z","avatar_url":"https://github.com/GregoryKogan.png","language":"C++","readme":"# result\n\n![GitHub License](https://img.shields.io/github/license/GregoryKogan/result)\n![Github Tests workflow](https://img.shields.io/github/actions/workflow/status/GregoryKogan/result-cpp/tests.yml?logo=github\u0026label=tests)\n![Github Tests workflow](https://img.shields.io/github/actions/workflow/status/GregoryKogan/result-cpp/docs.yml?logo=files\u0026logoColor=f5f5f5\u0026label=docs)\n\nResult-CPP is a C++ library that provides a `Result\u003cT, E\u003e` type, which can be used to return and propagate errors. It's inspired by Rust's `std::Result` type.\nIt's a header-only library, so you can just copy the `result.h` file into your project and start using it.\nOr you can use it as a git submodule.\nOr fetch it with [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) if you're using CMake.\n\n## Documentation\n\nYou can find the documentation [here](https://gregorykogan.github.io/result-cpp/).\n\nAnd the project's repo [here](https://github.com/GregoryKogan/result-cpp).\n\nIt's auto generated with [Doxygen](https://www.doxygen.nl/index.html) by GitHub Actions and hosted on GitHub Pages.\nIt uses the [Doxygen Awesome](https://jothepro.github.io/doxygen-awesome-css/) theme, that I customized to use Tokyo Night palette.\n\n## Features\n\n- `Result\u003cT, E\u003e` type for returning and propagating errors.\n- `Ok` and `Err` static methods for creating successful and unsuccessful `Result` objects respectively.\n- `is_ok` and `is_err` methods for checking if the `Result` is successful or unsuccessful.\n- `unwrap`, `unwrap_or` and `unwrap_err` methods for extracting the value or error from the `Result`.\n\n## Usage\n\n```cpp\n#include \u003ciostream\u003e\n#include \"result.h\"\n\nres::Result\u003cint, std::string\u003e divide(int a, int b) {\n  if (b == 0) {\n    return res::Err(std::string(\"Division by zero\"));\n  } else {\n    return res::Ok(a / b);\n  }\n}\n\nint main() {\n  auto result = divide(10, 2);\n\n  if (result.is_ok()) {\n    std::cout \u003c\u003c \"Result: \" \u003c\u003c result.unwrap() \u003c\u003c '\\n';\n  } else {\n    std::cout \u003c\u003c \"Error: \" \u003c\u003c result.unwrap_err() \u003c\u003c '\\n';\n  }\n}\n```\n\nYou can find many other use cases within [/tests](https://github.com/GregoryKogan/result-cpp/tree/main/tests) directory\n\n## Contributing\n\nI'm not planning to write any more features for this library, but I will gladly accept any pull requests that add new features or fix bugs.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorykogan%2Fresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregorykogan%2Fresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorykogan%2Fresult/lists"}