diff --git a/src/pvxs/sharedArray.h b/src/pvxs/sharedArray.h index ea91a2c..a44fe39 100644 --- a/src/pvxs/sharedArray.h +++ b/src/pvxs/sharedArray.h @@ -474,15 +474,11 @@ public: template::value && (std::is_const::value == std::is_const::value), int>::type =0> shared_array convertTo() const { - if(detail::CaptureBase::code==detail::CaptureBase::code) { - return castTo(); - } else { - shared_array ret(this->_count); - detail::convertArr(detail::CaptureBase::code, (void*)ret._data.get(), - detail::CaptureBase::code, this->_data.get(), - this->_count); - return ret; - } + shared_array ret(this->_count); + detail::convertArr(detail::CaptureBase::code, (void*)ret._data.get(), + detail::CaptureBase::code, this->_data.get(), + this->_count); + return ret; } //! Provide options when rendering with std::ostream. diff --git a/test/testshared.cpp b/test/testshared.cpp index b0e0fd3..e060f4c 100644 --- a/test/testshared.cpp +++ b/test/testshared.cpp @@ -196,11 +196,39 @@ void testFromVector() testEq(V.size(), 3u); } +void testConvert() +{ + testDiag("%s", __func__); + + static_assert (detail::CaptureCode::code!=detail::CaptureCode::code, ""); + + testArrEq(shared_array({1u, 2u, 0xffffffffu}).convertTo(), + shared_array({1u, 2u, 0xffffffffu})); + + testArrEq(shared_array({1u, 2u, 0xffffffffu}).convertTo(), + shared_array({1u, 2u, 0xffffu})); + + testArrEq(shared_array({1u, 2u, 0xffffffffu}).convertTo(), + shared_array({1, 2, -1})); + + testArrEq(shared_array({1u, 2u, 0xffffffffu}).convertTo(), + shared_array({1, 2, -1})); + + testArrEq(shared_array({1, 2, -1}).convertTo(), + shared_array({1u, 2u, 0xffffffffu})); + + testArrEq(shared_array({1, 2, -1}).convertTo(), + shared_array({1.0, 2.0, -1.0})); + + testArrEq(shared_array({1, 2, -1}).convertTo(), + shared_array({"1", "2", "-1"})); +} + } // namespace MAIN(testshared) { - testPlan(97); + testPlan(104); testSetup(); testEmpty(); testEmpty(); @@ -215,5 +243,6 @@ MAIN(testshared) testComplex(); testCast(); testFromVector(); + testConvert(); return testDone(); }