|
commons 0.1.5
Header-only C++23 library of common/shared types for the C++ libraries
|
A value type for a Semantic Versioning 2.0.0 version — major.minor.patch with optional prerelease and build metadata.
More...
#include <commons/types.hpp>#include <algorithm>#include <array>#include <compare>#include <format>#include <functional>#include <optional>#include <ostream>#include <string>#include <string_view>

Go to the source code of this file.
Classes | |
| struct | comms::SemVer |
A semantic version: major.minor.patch with optional prerelease/build. More... | |
| struct | std::formatter< comms::SemVer > |
Formats comms::SemVer as its canonical version string. Takes no format spec. More... | |
| struct | std::hash< comms::SemVer > |
Hash consistent with operator==: it combines major/minor/patch and the prerelease string, and (like equality) excludes build metadata. More... | |
Functions | |
| std::string | comms::to_string (const SemVer &v) |
SemVer as its canonical version string. | |
A value type for a Semantic Versioning 2.0.0 version — major.minor.patch with optional prerelease and build metadata.
comms::SemVer holds the three numeric components plus the textual prerelease (the part after -, before +) and build (the part after +). Because those are std::string members it is a plain runtime value type — not a constexpr literal type like Color/Icon — so parsing and comparison are ordinary runtime functions and there is no UDL literal.
SemVer::parse is non-throwing (mirrors Icon::parse) and applies the full spec where it matters:
alpha < alpha.1).1.0.0+a == 1.0.0+b); it is still preserved by to_string.As a convenience the numeric core is parsed leniently: "1" and "1.2" fill the missing components with 0. Prerelease/build identifiers are still validated per spec (dot-separated, each non-empty and [0-9A-Za-z-], numeric prerelease identifiers without leading zeros); any violation yields std::nullopt.
Serialization (in commons/json.hpp, gated by COMMONS_WITH_NLOHMANN_JSON): SemVer travels as its canonical version string.
Text output (always available): to_string, operator<<, and std::format all emit the canonical version string.