diff options
author | Johnny Matthews <guitargeek> | 2021-09-15 19:13:10 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-09-15 19:13:10 +0300 |
commit | a6adb7ecaef38e419d9268074193942669be6e7f (patch) | |
tree | 449c8dc305fb5c5233bde31fdd988899213b50e7 /source/blender/blenlib/BLI_span.hh | |
parent | 09f14b38f2d0c22b396dcd6c15bf959631ed1bfd (diff) |
BLI: Add a reverse method to MutableSpan
Add a method that allows a MutableSpan to reverse itself. This reverses
the data in the original span object. This is a first step in extracting
some functionality from nodes and making it more general.
Differential Revision: https://developer.blender.org/D12485
Diffstat (limited to 'source/blender/blenlib/BLI_span.hh')
-rw-r--r-- | source/blender/blenlib/BLI_span.hh | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index e04295b0e51..5adb47ba0b0 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -644,6 +644,16 @@ template<typename T> class MutableSpan { } /** + * Reverse the data in the MutableSpan. + */ + constexpr void reverse() + { + for (const int i : IndexRange(size_ / 2)) { + std::swap(data_[size_ - 1 - i], data_[i]); + } + } + + /** * Returns an (immutable) Span that references the same array. This is usually not needed, * due to implicit conversions. However, sometimes automatic type deduction needs some help. */ |