shared_vector_convert<>() fix convert of empty array
Empty arrays can be untyped, but this doesn't matter.
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user