protocol/RangeArg: add static method Single()

This commit is contained in:
Max Kellermann 2021-02-15 19:44:20 +01:00
parent ad059d5804
commit b57eeaa720
2 changed files with 8 additions and 1 deletions

View File

@ -107,7 +107,7 @@ ParseCommandArgRange(const char *s)
range.end = (unsigned)value;
} else {
range.end = (unsigned)value + 1;
return RangeArg::Single(range.start);
}
return range;

View File

@ -36,6 +36,13 @@ struct RangeArg {
return OpenEnded(0);
}
/**
* Construct an instance describing exactly one index.
*/
static constexpr RangeArg Single(unsigned i) noexcept {
return { i, i + 1 };
}
constexpr bool operator==(RangeArg other) const noexcept {
return start == other.start && end == other.end;
}