{"id":16265711,"url":"https://github.com/z4kn4fein/cpp-semver","last_synced_at":"2026-04-02T02:38:24.009Z","repository":{"id":51686261,"uuid":"520532901","full_name":"z4kn4fein/cpp-semver","owner":"z4kn4fein","description":"Semantic Versioning library for modern C++.","archived":false,"fork":false,"pushed_at":"2024-08-22T16:25:48.000Z","size":42,"stargazers_count":44,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-27T09:37:10.268Z","etag":null,"topics":["cplusplus","cplusplus-17","cpp","cpp17","header-only","header-only-library","semantic-version","semantic-versioning","semver","single-file-library"],"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/z4kn4fein.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":"2022-08-02T14:32:15.000Z","updated_at":"2025-02-03T09:53:55.000Z","dependencies_parsed_at":"2024-10-10T17:20:31.655Z","dependency_job_id":"ff24cdb8-2215-447a-9210-04f9e7298345","html_url":"https://github.com/z4kn4fein/cpp-semver","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z4kn4fein%2Fcpp-semver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z4kn4fein%2Fcpp-semver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z4kn4fein%2Fcpp-semver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z4kn4fein%2Fcpp-semver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z4kn4fein","download_url":"https://codeload.github.com/z4kn4fein/cpp-semver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243815605,"owners_count":20352195,"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":["cplusplus","cplusplus-17","cpp","cpp17","header-only","header-only-library","semantic-version","semantic-versioning","semver","single-file-library"],"created_at":"2024-10-10T17:20:22.150Z","updated_at":"2026-04-02T02:38:24.004Z","avatar_url":"https://github.com/z4kn4fein.png","language":"C++","readme":"# cpp-semver\n\n[![Build](https://img.shields.io/github/actions/workflow/status/z4kn4fein/cpp-semver/ci.yml?logo=GitHub\u0026label=windows%20%2F%20macos%20%2F%20linux\u0026branch=main)](https://github.com/z4kn4fein/cpp-semver/actions/workflows/ci.yml)\n[![Build](https://img.shields.io/github/actions/workflow/status/z4kn4fein/cpp-semver/sanitize.yml?logo=GitHub\u0026label=sanitize\u0026branch=main)](https://github.com/z4kn4fein/cpp-semver/actions/workflows/sanitize.yml)\n[![codecov](https://codecov.io/gh/z4kn4fein/cpp-semver/branch/main/graph/badge.svg?token=N3EF1SOX18)](https://codecov.io/gh/z4kn4fein/cpp-semver)\n[![vcpkg](https://img.shields.io/badge/package-vcpkg-blue)](https://github.com/microsoft/vcpkg/tree/master/ports/z4kn4fein-semver)\n[![godbolt](https://img.shields.io/badge/try-on_godbolt-blue)](https://godbolt.org/z/ad9YYdc91)\n\nSemantic Versioning library for modern C++.\nIt implements the full [semantic version 2.0.0](https://semver.org/spec/v2.0.0.html) specification and\nprovides the ability to **parse**, **compare**, and **increment** semantic versions.\n\n## Features\n- C++17\n- Single-file / header-only\n- No external dependencies\n\n## Installation\n1. Include `semver.hpp`\n\n   As `semver` is a header-only library, you can download and copy [`semver.hpp`](https://github.com/z4kn4fein/cpp-semver/blob/main/include/semver/semver.hpp) \n   to your project's include path.\n\n2. With `cmake`\n\n   ```cmake\n   include(FetchContent)\n   \n   FetchContent_Declare(\n       cpp-semver\n       GIT_REPOSITORY https://github.com/z4kn4fein/cpp-semver.git\n       GIT_TAG v0.4.0)\n   FetchContent_MakeAvailable(cpp-semver)\n   ```\n   \n   This will produce the target `semver` which you can link against the typical way:\n\n   ```cmake\n   target_link_libraries(your_target_name PRIVATE semver)\n   ```\n\n   To use the lib as a **C++20 module**, you have to turn the `SEMVER_BUILD_MODULE` option `ON`:\n   ```cmake\n   set(SEMVER_BUILD_MODULE ON)\n   \n   FetchContent_Declare(#[[...]])\n   ```\n   Then, you can import the package:\n   ```cpp\n   import semver;\n   ```\n\n3. With `vcpkg`\n\n   If you are using vcpkg for external dependencies, then you can install the package with:\n   ```bash\n   vcpkg install z4kn4fein-semver\n   ```\n\n4. With `Bazel`\n\n   ```python\n   bazel_dep(name = \"cpp-semver\", version = \"\u003ccpp-semver-version\u003e\")\n\n   git_override(\n    module_name = \"cpp-semver\",\n    remote = \"https://github.com/z4kn4fein/cpp-semver.git\",\n    tag = \"\u003ccpp-semver-version\u003e\"\n   )\n   ```\n   \n   Then, you can add `cpp-semver` to your dependency list:\n   ```python\n   cc_library(\n    name = \"example-library\",\n    deps = [\"@cpp-semver//:cpp-semver\"], \n   )\n   ```\n\n   \u003e C++ module support for *Bazel* has not been added yet.\n\n## Usage\nThe following options are available to construct a `version`:\n1. Building part by part.\n\n   ```cpp\n   auto version = semver::version(3, 5, 2, \"alpha\", \"build\");\n   ```\n\n2. Parsing from a string with `semver::version::parse()`:\n\n   ```cpp\n   auto version = semver::version::parse(\"3.5.2-alpha+build\");\n   ```\n\n3. Using the `_v` user-defined literal on a string.\n\n   ```cpp\n   using namespace semver::literals; // required to use the literals\n   \n   auto version = \"3.5.2-alpha+build\"_v;\n   ```\n\nThe constructed `version` provides the following information:\n```cpp\nsemver::version version = \"3.5.2-alpha.2+build\"_v;\n\nstd::cout \u003c\u003c version;                     // 3.5.2-alpha.2+build\nstd::cout \u003c\u003c version.major();             // 3\nstd::cout \u003c\u003c version.minor();             // 5\nstd::cout \u003c\u003c version.patch();             // 2\nstd::cout \u003c\u003c version.prerelease();        // \"alpha.2\"\nstd::cout \u003c\u003c version.build_meta();        // \"build\"\n\nstd::cout \u003c\u003c version.is_prerelease();     // true\nstd::cout \u003c\u003c version.is_stable();         // false\n\nstd::cout \u003c\u003c version.without_suffixes();  // \"3.5.2\"\n```\n\n### Strict vs. Loose Parsing\nBy default, the version parser considers partial versions like `1.0` and versions starting with the `v` prefix invalid.\nThis behaviour can be turned off by setting the parser's `strict` parameter to `false` or by using the `_lv` user-defined literal.\n```cpp\nstd::cout \u003c\u003c \"v2.3-alpha\"_v;                                  // exception\nstd::cout \u003c\u003c \"2.1\"_v;                                         // exception\nstd::cout \u003c\u003c \"v3\"_v;                                          // exception\n\nstd::cout \u003c\u003c semver::version::parse(\"v2.3-alpha\", false);     // 2.3.0-alpha\nstd::cout \u003c\u003c \"2.1\"_lv;                                        // 2.1.0\nstd::cout \u003c\u003c \"v3\"_lv;                                         // 3.0.0\n```\n\n## Compare\n\nIt is possible to compare two `version` objects with comparison operators.\n```cpp\n\"0.1.0\"_v \u003c \"0.1.1\"_v;                   // true\n\"0.1.1\"_v \u003c= \"0.1.1\"_v;                  // true\n\"0.1.0-alpha.3\"_v \u003c \"0.1.0-alpha.4\"_v;   // true\n```\n\nThe equality of two `version` objects can be determined with equality operators.\n```cpp\n\"0.1.1\"_v == \"0.1.1\"_v;       // true\n\"0.1.1\"_v != \"0.1.1\"_v;       // false\n```\n\n## Increment\n`version` objects can produce incremented versions of themselves with the `next_major()`,\n`next_minor()`, `next_patch()`, `next_prerelease()`, and `increment()` methods.\nThese methods can be used to determine the next version in order by increasing the appropriate identifier.\n`version` objects are **immutable**, so each incrementing function creates a new `version`.\n\nThis example shows how the incrementation works on a stable version:\n```cpp\nauto stable = \"1.0.0\"_v;\n\nstd::cout \u003c\u003c stable.next_major();                          // 2.0.0\nstd::cout \u003c\u003c stable.next_minor();                          // 1.1.0\nstd::cout \u003c\u003c stable.next_patch();                          // 1.0.1\nstd::cout \u003c\u003c stable.next_prerelease();                     // 1.0.1-0\n\n// or with the increment() method:\nstd::cout \u003c\u003c stable.increment(semver::inc::major);         // 2.0.0\nstd::cout \u003c\u003c stable.increment(semver::inc::minor);         // 1.1.0\nstd::cout \u003c\u003c stable.increment(semver::inc::patch);         // 1.0.1\nstd::cout \u003c\u003c stable.increment(semver::inc::prerelease);    // 1.0.1-0\n```\n\nIn case of an unstable version:\n```cpp\nauto unstable = \"1.0.0-alpha.2+build.1\"_v;\n\nstd::cout \u003c\u003c unstable.next_major();                         // 2.0.0\nstd::cout \u003c\u003c unstable.next_minor();                         // 1.1.0\nstd::cout \u003c\u003c unstable.next_patch();                         // 1.0.0\nstd::cout \u003c\u003c unstable.next_prerelease();                    // 1.0.0-alpha.3\n\n// or with the increment() method:\nstd::cout \u003c\u003c unstable.increment(semver::inc::major);        // 2.0.0\nstd::cout \u003c\u003c unstable.increment(semver::inc::minor);        // 1.1.0\nstd::cout \u003c\u003c unstable.increment(semver::inc::patch);        // 1.0.0\nstd::cout \u003c\u003c unstable.increment(semver::inc::prerelease);   // 1.0.0-alpha.3\n```\n\nEach incrementing function provides the option to set a pre-release identity on the incremented version.\n```cpp\nauto version = \"1.0.0-alpha.1\"_v;\n\nstd::cout \u003c\u003c version.next_major(\"beta\");                            // 2.0.0-beta\nstd::cout \u003c\u003c version.next_minor(\"\");                                // 1.1.0\nstd::cout \u003c\u003c version.next_patch(\"alpha\");                           // 1.0.1-alpha\nstd::cout \u003c\u003c version.next_prerelease(\"alpha\");                      // 1.0.0-alpha.2\n\n// or with the increment() method:\nstd::cout \u003c\u003c version.increment(semver::inc::major, \"beta\");         // 2.0.0-beta\nstd::cout \u003c\u003c version.increment(semver::inc::minor, \"\");             // 1.1.0\nstd::cout \u003c\u003c version.increment(semver::inc::patch, \"alpha\");        // 1.0.1-alpha\nstd::cout \u003c\u003c version.increment(semver::inc::prerelease, \"alpha\");   // 1.0.0-alpha.2\n```\n\n## Exceptions\nWhen the version parsing fails due to an invalid format, the library throws a specific `semver_exception`.\n\n## Contact \u0026 Support\n- Create an [issue](https://github.com/z4kn4fein/cpp-semver/issues) for bug reports and feature requests.\n- Start a [discussion](https://github.com/z4kn4fein/cpp-semver/discussions) for your questions and ideas.\n- Add a ⭐️ to support the project!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz4kn4fein%2Fcpp-semver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz4kn4fein%2Fcpp-semver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz4kn4fein%2Fcpp-semver/lists"}