diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-14 14:16:44 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-14 14:16:44 +0300 |
commit | cc6c52768a9e6d5c82f35e953a6e53ece76d3a78 (patch) | |
tree | 2318e47733e2c63eda60011b22797bad22022cbd /source/blender/blenlib/tests/BLI_array_test.cc | |
parent | 2d653364086d62cc9b503724c962cc466ad3e4b4 (diff) |
BLI: add reverse iterators, iterator constructor and Vector.insert/prepend
The new reverse iterators behave as the reverse iterators for contains from
the standard library. Have a look at the tests to see how to use them.
Using them will hopefully become easier with ranges in C++20.
A Vector can now be constructed from two iterators, which is very common
in the standard library.
New Vector.insert methods allow adding elements in the middle of a vector.
These methods should not be used often in practice, because they has a linear running time.
New Vector.prepend methods allow adding elements to the beginning of a vector.
These methods are O(n) as well.
Diffstat (limited to 'source/blender/blenlib/tests/BLI_array_test.cc')
-rw-r--r-- | source/blender/blenlib/tests/BLI_array_test.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_array_test.cc b/source/blender/blenlib/tests/BLI_array_test.cc index 7348a6f93f3..38ab695d238 100644 --- a/source/blender/blenlib/tests/BLI_array_test.cc +++ b/source/blender/blenlib/tests/BLI_array_test.cc @@ -2,6 +2,7 @@ #include "BLI_array.hh" #include "BLI_strict_flags.h" +#include "BLI_vector.hh" #include "testing/testing.h" namespace blender::tests { @@ -173,4 +174,18 @@ TEST(array, Fill) EXPECT_EQ(array[4], 3); } +TEST(array, ReverseIterator) +{ + Array<int> array = {3, 4, 5, 6}; + Vector<int> reversed_vec; + + for (auto it = array.rbegin(); it != array.rend(); ++it) { + reversed_vec.append(*it); + *it += 10; + } + + EXPECT_EQ_ARRAY(reversed_vec.data(), Span({6, 5, 4, 3}).data(), 4); + EXPECT_EQ_ARRAY(array.data(), Span({13, 14, 15, 16}).data(), 4); +} + } // namespace blender::tests |