Files
Breeze/source/BreezeCore/include/breeze/Version.hpp
T
2026-10-24 09:53:48 -03:00

36 lines
1.0 KiB
C++

#pragma once
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace breeze
{
/// A semantic version: major.minor.patch with an optional pre-release tag.
/// A pre-release sorts before the release it leads up to (1.0.0-rc1 < 1.0.0).
struct Version
{
int major = 0;
int minor = 0;
int patch = 0;
std::string pre;
[[nodiscard]] std::string toString() const;
};
/// Accepts "1.2.3", "v1.2.3", "1.2.3-rc1", "1.2" (patch 0) and "1" (minor and patch 0);
/// anything else, including build metadata after '+', is dropped or rejected.
std::optional<Version> parseVersion(std::string_view text);
int compare(const Version& a, const Version& b);
bool operator<(const Version& a, const Version& b);
bool operator==(const Version& a, const Version& b);
/// The greatest of `versions`; with `sameMajorAs`, only of those with that major version.
std::optional<Version> greatest(const std::vector<Version>& versions,
std::optional<int> sameMajorAs = std::nullopt);
}