{"id":24772528,"url":"https://github.com/rvarago/cpp_optional_extras","last_synced_at":"2025-10-09T19:07:21.505Z","repository":{"id":273998048,"uuid":"920487381","full_name":"rvarago/cpp_optional_extras","owner":"rvarago","description":"*EXPERIMENTAL* A handful of C++ utilities I wish std::optional\u003cT\u003e had","archived":false,"fork":false,"pushed_at":"2025-03-04T10:29:54.000Z","size":38,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T11:33:49.575Z","etag":null,"topics":["cpp","cpp20-library","functional-programming","optional"],"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/rvarago.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":"2025-01-22T08:39:02.000Z","updated_at":"2025-03-04T10:29:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d5ccbb5-b8ce-4536-8ce2-d914a054612e","html_url":"https://github.com/rvarago/cpp_optional_extras","commit_stats":null,"previous_names":["rvarago/cpp_optional_extras"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Fcpp_optional_extras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Fcpp_optional_extras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Fcpp_optional_extras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvarago%2Fcpp_optional_extras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rvarago","download_url":"https://codeload.github.com/rvarago/cpp_optional_extras/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245168814,"owners_count":20571799,"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":["cpp","cpp20-library","functional-programming","optional"],"created_at":"2025-01-29T04:23:15.190Z","updated_at":"2025-10-09T19:07:16.470Z","avatar_url":"https://github.com/rvarago.png","language":"C++","readme":"# cpp_optional_extras\n\nA handful of C++ utilities I wish [`std::optional\u003cT\u003e`](https://en.cppreference.com/w/cpp/utility/optional) had.\n\n## Purpose\n\nC++17 brought us `std::optional\u003cT\u003e`, then C++23 enhanced it with a couple of member-functions (e.g. `transform`) to safely express common data transformations.\n\nThis library draws inspiration from other languages ​​and provides a handful of additional functions to make working with `std::optional\u003cT\u003e` even more ergonomic and less error-prone by encapsulating common patterns into reusable algorithms around correct access to the underlying `T`.\n\n### Examples\n\nYou have an function `get_access_token` that returns an `access_token` and you want to `verify_signature` and do something when it's valid. With `exists`:\n\n```cpp\nauto get_access_token() -\u003e std::optional\u003caccess_token\u003e;\nauto verify_signature(access_token const \u0026) -\u003e bool;\n\nif (optx::exists(get_access_token(), verify_signature)) {\n    // do something\n}\n```\n\nYou have a `person` with optional `first_name` and `second_name`, and you want to format them when both are available or return the first available one, otherwise return `N/A` when neither is available. With `append`:\n\n```cpp\nstruct person {\n  std::optional\u003cstd::string\u003e first_name;\n  std::optional\u003cstd::string\u003e second_name;\n\n  auto format_name() const -\u003e std::string {\n    return optx::append(first_name, second_name,\n                        [](auto const fname, auto const sname) {\n                          return fname + \" \" + sname;\n                        })\n        .value_or(std::string{\"N/A\"});\n  }\n};\n```\n\nThese are just two of the available algorithms!\n\n### Functions\n\n- `filter(optional\u003cT\u003e, T -\u003e bool) -\u003e optional\u003cT\u003e`\n- `exists(optional\u003cT\u003e, T -\u003e bool) -\u003e bool`\n- `contains(optional\u003cT\u003e, T) -\u003e bool`\n- `zip_with(optional\u003cL\u003e, optional\u003cR\u003e, (L, R) -\u003e O) -\u003e optional\u003cO\u003e`\n- `zip(optional\u003cL\u003e, optional\u003cR\u003e) -\u003e optional\u003cpair\u003cL, R\u003e\u003e`\n- `unzip(optional\u003cpair\u003cL, R\u003e) -\u003e pair\u003coptional\u003cL\u003e, optional\u003cR\u003e\u003e`\n- `append(optional\u003cT\u003e, optional\u003cT\u003e, (T, T) -\u003e T) -\u003e optional\u003cT\u003e`\n- `fold(optional\u003cT\u003e, () -\u003e R, T -\u003e R) -\u003e R`\n\n## Requirements\n\nC++20\n\n## Usage\n\nThis is a header-only library. Algorithms live in [`algorithm.hpp`](include/rvarago/optional_extras/algorithm.hpp).\n\n- (Optional) Link against the INTERFACE `rvarago::optional_extras` target in your CMake build.\n- Include `rvarago/optional_extras/algorithm.hpp`\n- Call into functions from the `rvarago::optional_extras::algorithm` namespace, perhaps alias it as `namespace optx = rvarago::optional_extras::algorithm;` to save keystrokes.\n\n## Contributing\n\nThis repository has a [`flake.nix`](./flake.nix) with everything I need for development/CI (toolchain, language server, etc).\n\nFurthermore, with:\n\n```sh\nnix develop -c check\n```\n\nYou run all CI checks locally.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvarago%2Fcpp_optional_extras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frvarago%2Fcpp_optional_extras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvarago%2Fcpp_optional_extras/lists"}