From 403384998a6bb5f428e15ced5503206b45032b25 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 8 Jul 2020 22:27:25 +0200 Subject: BLI: improve constructors and conversions to span This allows us to avoid many calls to `as_span()` methods. I will remove those in the next commit. Furthermore, constructors of Vector and Array can convert from one type to another now. I tested these changes on Linux with gcc and on Windows. --- source/blender/blenlib/BLI_array.hh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'source/blender/blenlib/BLI_array.hh') diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh index 18f9aad1000..c7a9c49c972 100644 --- a/source/blender/blenlib/BLI_array.hh +++ b/source/blender/blenlib/BLI_array.hh @@ -89,17 +89,19 @@ class Array { /** * Create a new array that contains copies of all values. */ - Array(Span values, Allocator allocator = {}) : allocator_(allocator) + template> * = nullptr> + Array(Span values, Allocator allocator = {}) : allocator_(allocator) { size_ = values.size(); data_ = this->get_buffer_for_size(values.size()); - uninitialized_copy_n(values.data(), size_, data_); + uninitialized_convert_n(values.data(), size_, data_); } /** * Create a new array that contains copies of all values. */ - Array(const std::initializer_list &values) : Array(Span(values)) + template> * = nullptr> + Array(const std::initializer_list &values) : Array(Span(values)) { } @@ -219,6 +221,18 @@ class Array { return MutableSpan(data_, size_); } + template> * = nullptr> + operator Span() const + { + return Span(data_, size_); + } + + template> * = nullptr> + operator MutableSpan() + { + return MutableSpan(data_, size_); + } + Span as_span() const { return *this; -- cgit v1.2.3