[Bf-blender-cvs] [da3d297b3f3] functions: subscript operator for range
Jacques Lucke
noreply at git.blender.org
Sun Apr 28 18:57:37 CEST 2019
Commit: da3d297b3f3dc89c67a78b2aa3bf97eb705e4323
Author: Jacques Lucke
Date: Sun Apr 28 17:50:44 2019 +0200
Branches: functions
https://developer.blender.org/rBda3d297b3f3dc89c67a78b2aa3bf97eb705e4323
subscript operator for range
===================================================================
M source/blender/blenlib/BLI_range.hpp
M tests/gtests/blenlib/BLI_range_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_range.hpp b/source/blender/blenlib/BLI_range.hpp
index 0959b0f0743..0253aededc0 100644
--- a/source/blender/blenlib/BLI_range.hpp
+++ b/source/blender/blenlib/BLI_range.hpp
@@ -54,6 +54,12 @@ template<typename T> class Range {
return RangeIterator(*this, m_one_after_last);
}
+ T operator[](uint index) const
+ {
+ BLI_assert(index < this->size());
+ return m_start + index;
+ }
+
uint size() const
{
return m_one_after_last - m_start;
diff --git a/tests/gtests/blenlib/BLI_range_test.cc b/tests/gtests/blenlib/BLI_range_test.cc
index e8d66cc1854..a1e6fdb66a0 100644
--- a/tests/gtests/blenlib/BLI_range_test.cc
+++ b/tests/gtests/blenlib/BLI_range_test.cc
@@ -47,3 +47,11 @@ TEST(range, MultipleElementRange)
EXPECT_EQ(vector[i], i + 6);
}
}
+
+TEST(range, SubscriptOperator)
+{
+ IntRange range(5, 10);
+ EXPECT_EQ(range[0], 5);
+ EXPECT_EQ(range[1], 6);
+ EXPECT_EQ(range[2], 7);
+}
More information about the Bf-blender-cvs
mailing list