shared_vector_convert<>() fix convert of empty array

Empty arrays can be untyped, but this doesn't matter.
This commit is contained in:
Michael Davidsaver
2020-09-29 13:27:27 -07:00
parent 45d0d76a7f
commit 320cc3c60b
2 changed files with 9 additions and 2 deletions

View File

@@ -837,9 +837,13 @@ namespace detail {
typedef typename meta::strip_const<TO>::type to_t;
ScalarType stype = src.original_type(),
dtype = (ScalarType)ScalarTypeID<TO>::value;
if(stype==dtype) {
if(src.empty()) {
return shared_vector<TO>();
} else if(stype==dtype) {
// no convert needed
return shared_vector<TO>(src, detail::_shared_vector_cast_tag());
} else {
// alloc and convert
shared_vector<to_t> ret(src.size()/ScalarTypeFunc::elementSize(stype));

View File

@@ -474,6 +474,9 @@ void testVectorConvert()
testOk1(ints.unique());
testOk1(strings.size()==ints.size());
testOk1(strings.at(0)=="42");
testDiag("convert empty array");
testOk1(pvd::shared_vector_convert<double>(pvd::shared_vector<pvd::int32>()).empty());
}
void testWeak()
@@ -695,7 +698,7 @@ void testCXX11Init()
MAIN(testSharedVector)
{
testPlan(191);
testPlan(192);
testDiag("Tests for shared_vector");
testDiag("sizeof(shared_vector<pvd::int32>)=%lu",