From d5309bf4cf9e36e161027cf7ad1775eb355433f1 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 21 Apr 2021 16:59:22 +0200 Subject: Functions: add slice method for generic spans --- source/blender/functions/FN_generic_span.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/blender/functions/FN_generic_span.hh b/source/blender/functions/FN_generic_span.hh index ea2bd49fa09..e2c49697ba9 100644 --- a/source/blender/functions/FN_generic_span.hh +++ b/source/blender/functions/FN_generic_span.hh @@ -85,6 +85,14 @@ class GSpan { BLI_assert(type_->is()); return Span(static_cast(data_), size_); } + + GSpan slice(const int64_t start, int64_t size) const + { + BLI_assert(start >= 0); + BLI_assert(size >= 0); + const int64_t new_size = std::max(0, std::min(size, size_ - start)); + return GSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size); + } }; /** @@ -153,6 +161,14 @@ class GMutableSpan { BLI_assert(type_->is()); return MutableSpan(static_cast(data_), size_); } + + GMutableSpan slice(const int64_t start, int64_t size) const + { + BLI_assert(start >= 0); + BLI_assert(size >= 0); + const int64_t new_size = std::max(0, std::min(size, size_ - start)); + return GMutableSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size); + } }; } // namespace blender::fn -- cgit v1.2.3