I need convert a variable type of const std::shared_ptr<const T> into boost::shared_ptr<T>.
In the following scanCallback(), I can not modify the param const std::shared_ptr<const io_adaptor::msg::PandarScan> msg. The msg is very big in memory, which contains large lidar points. PushScanPacket() func's arg is boost::shared_ptr<io_adaptor::msg::PandarScan>, which I also can not modify its type.
The following code does not compile successfully, does somebody know how to do this?
void HesaiLidarModule::scanCallback(
const std::shared_ptr<const io_adaptor::msg::PandarScan> msg){
std::remove_const<const std::shared_ptr<
const io_adaptor::msg::PandarScan>
>::type non_const_msg(msg);
boost::shared_ptr<io_adaptor::msg::PandarScan> msg_boost(non_const_msg.get());
hsdk->PushScanPacket(msg_boost);
}
UPDATE_1st: The following code can compile successfully, but i'm not sure whether std::remove_const<const io_adaptor::msg::PandarScan>::type non_const_obj(*msg); induces a copy operator, which is expensive for msg.
void HesaiLidarModule::scanCallback(
const std::shared_ptr<const io_adaptor::msg::PandarScan> msg){
std::remove_const<const io_adaptor::msg::PandarScan>::type non_const_obj(*msg);
io_adaptor::msg::PandarScan& copy = non_const_obj;
boost::shared_ptr<io_adaptor::msg::PandarScan> msg_boost(©);
hsdk->PushScanPacket(msg_boost);
}