{"id":35408617,"url":"https://github.com/sentomk/patternia","last_synced_at":"2026-03-13T15:33:34.104Z","repository":{"id":308387046,"uuid":"1032508818","full_name":"sentomk/patternia","owner":"sentomk","description":"Providing pattern matching for modern c++.","archived":false,"fork":false,"pushed_at":"2026-03-10T15:01:44.000Z","size":3573,"stargazers_count":129,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-10T21:27:02.676Z","etag":null,"topics":["cpp","cross-platform","pattern-matching"],"latest_commit_sha":null,"homepage":"https://patternia.tech/","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/sentomk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-05T12:10:00.000Z","updated_at":"2026-03-10T15:01:26.000Z","dependencies_parsed_at":"2025-08-05T18:08:21.464Z","dependency_job_id":"69fb313f-3d76-4810-9503-209f3a0bb05f","html_url":"https://github.com/sentomk/patternia","commit_stats":null,"previous_names":["sentomk/patternia"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/sentomk/patternia","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sentomk%2Fpatternia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sentomk%2Fpatternia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sentomk%2Fpatternia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sentomk%2Fpatternia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sentomk","download_url":"https://codeload.github.com/sentomk/patternia/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sentomk%2Fpatternia/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30469312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cpp","cross-platform","pattern-matching"],"created_at":"2026-01-02T13:25:16.051Z","updated_at":"2026-03-13T15:33:34.098Z","avatar_url":"https://github.com/sentomk.png","language":"C++","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\"\n            srcset=\"https://wordpress-1316673449.cos.ap-beijing.myqcloud.com/img/banner-dark.svg\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\"\n            srcset=\"https://wordpress-1316673449.cos.ap-beijing.myqcloud.com/img/banner-dark.svg\"\u003e\n    \u003cimg alt=\"Patternia logo\"\n         src=\"https://wordpress-1316673449.cos.ap-beijing.myqcloud.com/img/banner-dark.svg\"\n         width=\"300\"\n         style=\"max-width: 90%; height: auto; margin-top: 10px; transform: translateX(-2px);\"\u003e\n  \u003c/picture\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![C++17+](https://img.shields.io/badge/C%2B%2B-17%2B-blue.svg?style=flat-square\u0026logo=c%2B%2B\u0026logoColor=white)](https://isocpp.org/)\n[![Build](https://github.com/SentoMK/patternia/actions/workflows/ci.yml/badge.svg?branch=main\u0026style=flat-square)](https://github.com/SentoMK/patternia/actions)\n[![License](https://img.shields.io/github/license/SentoMK/patternia?style=flat-square)](LICENSE)\n[![Version](https://img.shields.io/github/v/release/SentoMK/patternia?style=flat-square\u0026color=orange)](https://github.com/SentoMK/patternia/releases)\n[![Docs](https://img.shields.io/badge/docs-online-blue?style=flat-square)](https://patternia.tech)\n\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n**Patternia** is a header-only pattern matching library for modern C++.\nIt keeps matching expression-oriented, explicit, and zero-overhead.\n\n## Syntax\n\n```cpp\n#include \u003cptn/patternia.hpp\u003e\n\nint classify(int x) {\n  using namespace ptn;\n\n  return match(x) | on(\n    lit(0) \u003e\u003e 0,\n    lit(1) \u003e\u003e 1,\n    _ \u003e\u003e -1\n  );\n}\n```\n\n`match(subject)` creates the evaluation context.\n`on(...)` provides the ordered case list.\n`pattern \u003e\u003e handler` defines one case.\n`_` is the required fallback case.\n\n## Highlights\n\n- Literal, structural, and `std::variant` matching in one DSL.\n- Explicit binding through `$` and `$(...)`.\n- Declarative guards via `PTN_LET`, `PTN_WHERE`, `_0`, `arg\u003cN\u003e`, `rng(...)`, and callables.\n- No RTTI, no virtual dispatch, no heap allocation.\n- Static literal and variant dispatch lowering for hot paths.\n\n## Quick Examples\n\n### Guarded value match\n\n```cpp\nusing namespace ptn;\n\nconst char *bucket(int x) {\n  return match(x) | on(\n    $[PTN_LET(value, value \u003c 0)] \u003e\u003e \"negative\",\n    $[PTN_LET(value, value \u003c 10)] \u003e\u003e \"small\",\n    _ \u003e\u003e \"large\"\n  );\n}\n```\n\n### Structural match\n\n```cpp\nusing namespace ptn;\n\nstruct Point { int x; int y; };\n\nint magnitude2(const Point \u0026p) {\n  return match(p) | on(\n    $(has\u003c\u0026Point::x, \u0026Point::y\u003e()) \u003e\u003e [](int x, int y) {\n      return x * x + y * y;\n    },\n    _ \u003e\u003e 0\n  );\n}\n```\n\n### Variant match\n\n```cpp\nusing namespace ptn;\n\nusing Value = std::variant\u003cint, std::string\u003e;\n\nstd::string describe(const Value \u0026v) {\n  return match(v) | on(\n    is\u003cint\u003e() \u003e\u003e \"int\",\n    $(is\u003cstd::string\u003e()) \u003e\u003e [](const std::string \u0026s) {\n      return \"str:\" + s;\n    },\n    _ \u003e\u003e [] { return std::string(\"other\"); }\n  );\n}\n```\n\n## Installation\n\nPatternia is header-only with no external dependencies.\n\n**vcpkg** (recommended):\n\n```bash\nvcpkg install patternia\n```\n\n```cmake\nfind_package(patternia CONFIG REQUIRED)\ntarget_link_libraries(your_target PRIVATE patternia::patternia)\n```\n\n**FetchContent**:\n\n```cmake\ninclude(FetchContent)\nFetchContent_Declare(patternia\n  GIT_REPOSITORY https://github.com/sentomk/patternia.git\n  GIT_TAG v0.9.0\n)\nFetchContent_MakeAvailable(patternia)\n\ntarget_link_libraries(your_target PRIVATE patternia::patternia)\n```\n\n**Direct clone**:\n\n```bash\ngit clone https://github.com/SentoMK/patternia.git\ncd patternia\ncmake -S . -B build\ncmake --build build\n```\n\nSee [Installation Guide](https://patternia.tech/guide/installation/) for `find_package`, submodule, and header-copy options.\n\n## Tests\n\n```bash\ncmake -S . -B build -DPTN_BUILD_TESTS=ON\ncmake --build build --target ptn_tests\nctest --test-dir build --output-on-failure\n```\n\n## Performance-Oriented Usage\n\nCache the case pack for repeated hot paths:\n\n```cpp\nusing namespace ptn;\n\nint fast_classify(int x) {\n  return match(x) | PTN_ON(\n    lit\u003c1\u003e() \u003e\u003e 1,\n    lit\u003c2\u003e() \u003e\u003e 2,\n    _ \u003e\u003e 0\n  );\n}\n```\n\n`PTN_ON(...)` is a convenience wrapper over `static_on(...)`.\nIt avoids rebuilding the matcher object on every call.\n\n## Documentation\n\n- [Getting Started](https://patternia.tech/guide/getting-started/)\n- [API Reference](https://patternia.tech/api/)\n- [Design Overview](https://patternia.tech/design-overview/)\n- [Tutorials](https://patternia.tech/tutorials/from-control-flow/)\n- [Performance Notes](https://patternia.tech/performance/)\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) before sending changes.\nThis project is governed by [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsentomk%2Fpatternia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsentomk%2Fpatternia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsentomk%2Fpatternia/lists"}