13 ms·
No, it works. It's just non-obvious that it does due to the reliance on 4 levels of braces. It is equivalent to the following: lhs.Major < rhs.Major o
by tsegers 6y ago
No, it works. It's just non-obvious that it does due to the reliance on 4 levels of braces.
It is equivalent to the following:
lhs.Major < rhs.Major
or (lhs.Major == rhs.Major and lhs.Minor < rhs.Minor)
or (lhs.Major == rhs.Major and lhs.Minor == rhs.Minor and lhs.Patch <= rhs.Patch)
Deduplicating (lhs.Major == rhs.Major) decreased readability enough to be confusing.
- Joker_vD 6y agoThere is so many ways to write this comparison that after a couple of times you really wish there were something in the standard library to help you so that you could write e.g. bool operator<=(version lhs, version rhs) { return std::tie(lhs.Major, lhs.Minor, lhs.Patch) <= std::tie(rhs.Major, rhs.Minor, rhs.Patch); } Wait, there is! And Python has something like this too, even more laconic: you don't need to write "std::tie", naked parentheses are enough.