diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-08 23:27:25 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-08 23:27:25 +0300 |
commit | 403384998a6bb5f428e15ced5503206b45032b25 (patch) | |
tree | 23e09b183faa196603aafb1572ed0f13b3964333 /source/blender/blenlib/BLI_span.hh | |
parent | 4b85ed819dc0746f6fc46eab1019aab4c4fcf9c9 (diff) |
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.
Diffstat (limited to 'source/blender/blenlib/BLI_span.hh')
-rw-r--r-- | source/blender/blenlib/BLI_span.hh | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index 9688c93ec14..5c841787520 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -100,6 +100,11 @@ template<typename T> class Span { { } + template<typename U, typename std::enable_if_t<is_convertible_pointer_v<U, T>> * = nullptr> + Span(const U *start, uint size) : start_((const T *)start), size_(size) + { + } + /** * Reference an initializer_list. Note that the data in the initializer_list is only valid until * the expression containing it is fully computed. @@ -128,8 +133,8 @@ template<typename T> class Span { * Span<T *> -> Span<const T *> * Span<Derived *> -> Span<Base *> */ - template<typename U, typename std::enable_if_t<std::is_convertible_v<U *, T>> * = nullptr> - Span(Span<U *> array) : Span((T *)array.data(), array.size()) + template<typename U, typename std::enable_if_t<is_convertible_pointer_v<U, T>> * = nullptr> + Span(Span<U> array) : start_((T *)array.data()), size_(array.size()) { } |