BLI: Add MutableSpan.copy_from method
This commit is contained in:
parent
4619562e2f
commit
cf123da640
|
@ -608,6 +608,17 @@ template<typename T> class MutableSpan {
|
|||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all values from another span into this span. This invokes undefined behavior when the
|
||||
* destination contains uninitialized data and T is not trivially copy constructible.
|
||||
* The size of both spans is expected to be the same.
|
||||
*/
|
||||
void copy_from(Span<T> values)
|
||||
{
|
||||
BLI_assert(size_ == values.size());
|
||||
initialized_copy_n(values.data(), size_, start_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new span to the same underlying memory buffer. No conversions are done.
|
||||
*/
|
||||
|
|
|
@ -295,4 +295,17 @@ TEST(span, VoidPointerSpan)
|
|||
func1({&a, &b, &c});
|
||||
}
|
||||
|
||||
TEST(span, CopyFrom)
|
||||
{
|
||||
std::array<int, 4> src = {5, 6, 7, 8};
|
||||
std::array<int, 4> dst = {1, 2, 3, 4};
|
||||
|
||||
EXPECT_EQ(dst[2], 3);
|
||||
MutableSpan(dst).copy_from(src);
|
||||
EXPECT_EQ(dst[0], 5);
|
||||
EXPECT_EQ(dst[1], 6);
|
||||
EXPECT_EQ(dst[2], 7);
|
||||
EXPECT_EQ(dst[3], 8);
|
||||
}
|
||||
|
||||
} // namespace blender::tests
|
||||
|
|
Loading…
Reference in New Issue