BLI: improve IndexRange

Defining `operator-` for the iterator allows it to be used in more generic
iterator code. The `index_range` method is the same that exists on many
other containers like `Vector`.
This commit is contained in:
Jacques Lucke
2023-05-21 15:13:57 +02:00
parent f6d824bca6
commit b58cfde48a

View File

@@ -105,6 +105,11 @@ class IndexRange {
return a.current_ == b.current_;
}
constexpr friend int64_t operator-(const Iterator &a, const Iterator &b)
{
return a.current_ - b.current_;
}
constexpr int64_t operator*() const
{
return current_;
@@ -151,6 +156,11 @@ class IndexRange {
return size_;
}
constexpr IndexRange index_range() const
{
return IndexRange(size_);
}
/**
* Returns true if the size is zero.
*/