{"id":24486142,"url":"https://github.com/oktal/optional","last_synced_at":"2025-10-16T06:37:33.248Z","repository":{"id":16677204,"uuid":"19433092","full_name":"oktal/optional","owner":"oktal","description":"Option type implementation in C++11","archived":false,"fork":false,"pushed_at":"2016-04-02T11:58:45.000Z","size":1447,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T19:52:41.868Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oktal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-04T18:39:40.000Z","updated_at":"2024-02-23T08:46:31.000Z","dependencies_parsed_at":"2022-08-25T19:01:45.820Z","dependency_job_id":null,"html_url":"https://github.com/oktal/optional","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oktal/optional","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktal%2Foptional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktal%2Foptional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktal%2Foptional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktal%2Foptional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oktal","download_url":"https://codeload.github.com/oktal/optional/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oktal%2Foptional/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279163185,"owners_count":26117391,"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","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-01-21T14:33:16.405Z","updated_at":"2025-10-16T06:37:33.213Z","avatar_url":"https://github.com/oktal.png","language":"C++","readme":"# Option type in C++\n\n## Introduction\n\nThis is my attempt of implementing Option types in C++\n\nOption types are very popular in functionnal programming languages like Haskell\nor Scala.\nAn Option type is a polymorphic type that can either represent no value (None)\nor some value (Some).\n\nIn functionnal programming, option types are for example used when a function\ncan fail or return an empty value. Haskell defines option type as follows :\n\n```haskell\ndata Maybe a = Just a | Nothing\n```\n\nScala defines it as follows :\n\n```Scala\nOption[A] = if (x == null) None else Some(x)\n```\n\nFor example, when performing a hash-table or map lookup, the lookup function\nwould return Some(ValueType) if the key is present in the map or None if not.\nThat way, no null pointer or reference is involved and you can't get a\nNullPointerException. Even Java 8 now has an Optional type, based on the one\nprovided by Guava, the google Java open source library.\n\nA proposal has been made for C++14 to provide a std::optional type but for some\nreason, it didn't make to the standard yet.\nSo I decided to give it a try and implement my own option type C++ with some\nfunny templating stuff.\n\n## Getting started\n\nIf you want to use it, all you need to do is copy the optional.h header file\nto your project source directory and guess what, that's it ! Since this is only\ntemplate, it only consists of a single header file.\n\nAs for the interface, the optional_test.cc should be straightforward as a\nstarting point.\n\n## Running tests\n\nTo compile and run the tests, you just need cmake. On Unix, run the following\ncommands:\n\n```\nmkdir build\ncd build\ncmake -G \"Unix Makefiles\" ..\n./run_optional_tests\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foktal%2Foptional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foktal%2Foptional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foktal%2Foptional/lists"}