aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/xrange.h
diff options
context:
space:
mode:
authorIlnur Khuziev <ilnur.khuziev@yandex.ru>2022-02-10 16:46:13 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:13 +0300
commit736dcd8ca259457a136f2f9f9168c44643914323 (patch)
treeddd46a036d68bfa83aa11b892f31243ea6b068a1 /util/generic/xrange.h
parent9bf2fa2b060c9881d3135c2208c624a1dd546ecc (diff)
downloadydb-736dcd8ca259457a136f2f9f9168c44643914323.tar.gz
Restoring authorship annotation for Ilnur Khuziev <ilnur.khuziev@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/xrange.h')
-rw-r--r--util/generic/xrange.h110
1 files changed, 55 insertions, 55 deletions
diff --git a/util/generic/xrange.h b/util/generic/xrange.h
index 5fc8c82912..578605f356 100644
--- a/util/generic/xrange.h
+++ b/util/generic/xrange.h
@@ -13,16 +13,16 @@
* for (auto i: xrange(MyVector.size())) { // instead for (size_t i = 0; i < MyVector.size(); ++i)
* DoSomething(i, MyVector[i]);
* }
- *
+ *
* TVector<int> arithmeticSeq = xrange(10); // instead: TVector<int> arithmeticSeq; for(size_t i = 0; i < 10; ++i) { arithmeticSeq.push_back(i); }
- *
+ *
*/
namespace NPrivate {
template <typename T>
class TSimpleXRange {
- using TDiff = decltype(T() - T());
-
+ using TDiff = decltype(T() - T());
+
public:
constexpr TSimpleXRange(T start, T finish) noexcept
: Start(start)
@@ -52,12 +52,12 @@ namespace NPrivate {
}
constexpr bool operator==(const TIterator& other) const noexcept {
- return Value == other.Value;
- }
-
- TIterator& operator++() noexcept {
+ return Value == other.Value;
+ }
+
+ TIterator& operator++() noexcept {
++Value;
- return *this;
+ return *this;
}
TIterator& operator--() noexcept {
@@ -66,25 +66,25 @@ namespace NPrivate {
}
constexpr TDiff operator-(const TIterator& b) const noexcept {
- return Value - b.Value;
- }
-
+ return Value - b.Value;
+ }
+
template <typename IntType>
constexpr TIterator operator+(const IntType& b) const noexcept {
- return TIterator(Value + b);
- }
-
+ return TIterator(Value + b);
+ }
+
template <typename IntType>
TIterator& operator+=(const IntType& b) noexcept {
- Value += b;
- return *this;
- }
-
+ Value += b;
+ return *this;
+ }
+
template <typename IntType>
constexpr TIterator operator-(const IntType& b) const noexcept {
- return TIterator(Value - b);
- }
-
+ return TIterator(Value - b);
+ }
+
template <typename IntType>
TIterator& operator-=(const IntType& b) noexcept {
Value -= b;
@@ -100,9 +100,9 @@ namespace NPrivate {
};
using value_type = T;
- using iterator = TIterator;
- using const_iterator = TIterator;
-
+ using iterator = TIterator;
+ using const_iterator = TIterator;
+
constexpr TIterator begin() const noexcept {
return TIterator(Start);
}
@@ -112,14 +112,14 @@ namespace NPrivate {
}
constexpr T size() const noexcept {
- return Finish - Start;
- }
-
- template <class Container>
+ return Finish - Start;
+ }
+
+ template <class Container>
operator Container() const {
- return Container(begin(), end());
- }
-
+ return Container(begin(), end());
+ }
+
private:
T Start;
T Finish;
@@ -161,12 +161,12 @@ namespace NPrivate {
}
constexpr bool operator==(const TIterator& other) const noexcept {
- return Value_ == other.Value_;
- }
-
- TIterator& operator++() noexcept {
+ return Value_ == other.Value_;
+ }
+
+ TIterator& operator++() noexcept {
Value_ += Parent_->Step_;
- return *this;
+ return *this;
}
TIterator& operator--() noexcept {
@@ -176,23 +176,23 @@ namespace NPrivate {
constexpr TDiff operator-(const TIterator& b) const noexcept {
return (Value_ - b.Value_) / Parent_->Step_;
- }
-
+ }
+
template <typename IntType>
constexpr TIterator operator+(const IntType& b) const noexcept {
return TIterator(*this) += b;
- }
-
+ }
+
template <typename IntType>
TIterator& operator+=(const IntType& b) noexcept {
Value_ += b * Parent_->Step_;
- return *this;
- }
-
+ return *this;
+ }
+
template <typename IntType>
constexpr TIterator operator-(const IntType& b) const noexcept {
return TIterator(*this) -= b;
- }
+ }
template <typename IntType>
TIterator& operator-=(const IntType& b) noexcept {
@@ -206,9 +206,9 @@ namespace NPrivate {
};
using value_type = T;
- using iterator = TIterator;
- using const_iterator = TIterator;
-
+ using iterator = TIterator;
+ using const_iterator = TIterator;
+
constexpr TIterator begin() const noexcept {
return TIterator(Start_, *this);
}
@@ -229,14 +229,14 @@ namespace NPrivate {
}
constexpr T size() const noexcept {
- return (Finish_ - Start_) / Step_;
- }
-
- template <class Container>
+ return (Finish_ - Start_) / Step_;
+ }
+
+ template <class Container>
operator Container() const {
- return Container(begin(), end());
- }
-
+ return Container(begin(), end());
+ }
+
private:
const T Start_;
const TDiff Step_;