11#pragma once
2- #include < cstdlib>
32#include < cstdint>
3+ #include < cstdlib>
44#include < string_view>
55
66namespace VersionUtil
@@ -10,10 +10,11 @@ struct Version {
1010 uint8_t major{};
1111 uint8_t minor{};
1212 uint8_t revision{};
13+ bool is_normal{true }; // i.e. not a pre-release
1314
1415 void set_field (unsigned index, unsigned val) {
1516 // sanity check:
16- if (val > 9999 )
17+ if (val > 255 )
1718 return ;
1819
1920 if (index == 0 )
@@ -29,7 +30,8 @@ struct Version {
2930 Version (uint8_t maj, uint8_t min, uint8_t rev)
3031 : major{maj}
3132 , minor{min}
32- , revision{rev} {
33+ , revision{rev}
34+ , is_normal{true } {
3335 }
3436
3537 Version (std::string_view vers) {
@@ -47,8 +49,11 @@ struct Version {
4749 auto num = strtol (token.data (), nullptr , 10 );
4850 set_field (i++, num);
4951
50- if (pos == std::string_view::npos)
52+ if (pos == std::string_view::npos) {
53+ // "normal" means not a pre-release, meaning there's no dash after the last number
54+ is_normal = vers.find_first_of (' -' ) == vers.npos ;
5155 break ;
56+ }
5257 }
5358 }
5459
@@ -58,11 +63,13 @@ struct Version {
5863 }
5964
6065 auto operator <=>(Version const &other) const {
61- if (major == other.major && minor == other.minor && revision == other.revision )
66+ if (major == other.major && minor == other.minor && revision == other.revision && is_normal == other. is_normal )
6267 return std::strong_ordering::equal;
6368
6469 if ((major < other.major ) || (major == other.major && minor < other.minor ) ||
65- (major == other.major && minor == other.minor && revision < other.revision ))
70+ (major == other.major && minor == other.minor && revision < other.revision ) ||
71+ (major == other.major && minor == other.minor && revision == other.revision && !is_normal &&
72+ other.is_normal ))
6673 return std::strong_ordering::less;
6774
6875 return std::strong_ordering::greater;
0 commit comments