9#include <nlohmann/json.hpp>
19using namespace std::literals;
20inline constexpr auto kMajor =
"major"sv;
21inline constexpr auto kMinor =
"minor"sv;
22inline constexpr auto kPatch =
"patch"sv;
32 std::optional<int> patch;
34 [[nodiscard]]
constexpr bool operator== (
const Version &other)
const
36 return major == other.major && minor == other.minor
37 && patch.value_or (0) == other.patch.value_or (0);
40 [[nodiscard]]
constexpr bool operator!= (
const Version &other)
const
42 return !(*
this == other);
45 [[nodiscard]]
constexpr bool operator< (
const Version &other)
const
47 if (major != other.major)
48 return major < other.major;
49 if (minor != other.minor)
50 return minor < other.minor;
51 auto this_patch = patch.value_or (0);
52 auto other_patch = other.patch.value_or (0);
53 return this_patch < other_patch;
56 [[nodiscard]]
constexpr bool operator> (
const Version &other)
const
61 [[nodiscard]]
constexpr bool operator<= (
const Version &other)
const
63 return !(other < *
this);
66 [[nodiscard]]
constexpr bool operator>= (
const Version &other)
const
68 return !(*
this < other);
73to_json (nlohmann::json &j,
const Version &v)
76 j = nlohmann::json::object ();
79 if (v.patch.has_value ())
86from_json (
const nlohmann::json &j, Version &v)
88 using namespace version_keys;
89 v.major = j.at (kMajor).get<
int> ();
90 v.minor = j.at (kMinor).get<
int> ();
91 if (j.contains (kPatch))
93 v.patch = j[kPatch].get<
int> ();
97 v.patch = std::nullopt;
Key constants for version JSON serialization.
Represents a semantic version with major, minor, and optional patch.