0
$\begingroup$

Rosanswers logo

Hi,

According to this page http://wiki.ros.org/msg fixed-length arrays in msg files can be interpreted as boost::array or std::vector.

Whenever I tried to apply any vector logic to a message with a fixed-length array (let's say uint8[8]) it would throw errors saying that the type is of boost::array.

How can I enforce std::vector type on fixed-sized fields inside ROS messages?

EDIT: here's an example: http://docs.ros.org/api/can_msgs/html/msg/Frame.html, I would like to have data field as std::vector without changing the field itself to uint8[].


Originally posted by Hypomania on ROS Answers with karma: 120 on 2019-01-19

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The documentation is not saying you can use either type, it is saying that depending on the version it will either be a boost::array or a std::vector. In your case the type is boost::array so you will need to access it using that object type.

You would need to copy the data into a std::vector if you wanted to use that functionality since boost::array is a fixed length data type so cannot support the features of std::vector.


Originally posted by PeteBlackerThe3rd with karma: 9529 on 2019-01-19

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Hypomania on 2019-01-19:
Thank you. One quick question, for that message format I would have to copy data from callback rather than pointing it with a pointer, right?

Comment by Hypomania on 2019-01-19:
Also, do you have any references where I could look at how to properly copy boost::arrays? I am not familiar with boost at all unfortunately.

Comment by PeteBlackerThe3rd on 2019-01-19:
The reference is here, it has size() method identical to std::vector and uses [square brackets] for element access. That should cover most tasks.

Comment by Hypomania on 2019-01-19:
@PeteBlackerThe3rd, really appreciated, that looks exactly what I need!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.