diff options
author | Jacques Lucke <jacques@blender.org> | 2022-07-07 20:19:01 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-07-07 20:19:18 +0300 |
commit | ba62e20af67e1de25f781456df7175fa1b31db67 (patch) | |
tree | 28e4dcd2701e94d4c4e5f9c2c41a9635da7e6389 /source/blender/blenlib/tests | |
parent | 7cfea48752ebc544104d57d19736c201a98bc3cd (diff) |
BLI: make some spans default constructible
`GSpan` and spans based on virtual arrays were not default constructible
before, which made them hard to use sometimes. It's generally fine for
spans to be empty.
The main thing the keep in mind is that the type pointer in `GSpan` may
be null now. Generally, code receiving spans as input can assume that
the type is not-null, but sometimes that may be valid. The old #type() method
that returned a reference to the type still exists. It asserts when the
type is null.
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r-- | source/blender/blenlib/tests/BLI_virtual_array_test.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_virtual_array_test.cc b/source/blender/blenlib/tests/BLI_virtual_array_test.cc index c3c6d84ea42..14f5480f751 100644 --- a/source/blender/blenlib/tests/BLI_virtual_array_test.cc +++ b/source/blender/blenlib/tests/BLI_virtual_array_test.cc @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ #include "BLI_array.hh" +#include "BLI_generic_virtual_array.hh" #include "BLI_strict_flags.h" #include "BLI_vector.hh" #include "BLI_vector_set.hh" @@ -222,4 +223,36 @@ TEST(virtual_array, MaterializeCompressed) } } +TEST(virtual_array, EmptySpanWrapper) +{ + { + VArray<int> varray; + VArraySpan<int> span1 = varray; + EXPECT_TRUE(span1.is_empty()); + VArraySpan<int> span2 = std::move(span1); + EXPECT_TRUE(span2.is_empty()); + } + { + VMutableArray<int> varray; + MutableVArraySpan<int> span1 = varray; + EXPECT_TRUE(span1.is_empty()); + MutableVArraySpan<int> span2 = std::move(span1); + EXPECT_TRUE(span2.is_empty()); + } + { + GVArray varray; + GVArraySpan span1 = varray; + EXPECT_TRUE(span1.is_empty()); + GVArraySpan span2 = std::move(span1); + EXPECT_TRUE(span2.is_empty()); + } + { + GVMutableArray varray; + GMutableVArraySpan span1 = varray; + EXPECT_TRUE(span1.is_empty()); + GMutableVArraySpan span2 = std::move(span1); + EXPECT_TRUE(span2.is_empty()); + } +} + } // namespace blender::tests |