ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to force std::vector type for fixed-length arrays in msg?

asked 2019-01-19 08:55:46 -0600

Hypomania gravatar image

updated 2019-01-19 09:18:01 -0600


According to this page 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:, I would like to have data field as std::vector without changing the field itself to uint8[].

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-01-19 09:18:12 -0600

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.

edit flag offensive delete link more


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?

Hypomania gravatar image Hypomania  ( 2019-01-19 09:25:12 -0600 )edit

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.

Hypomania gravatar image Hypomania  ( 2019-01-19 09:26:43 -0600 )edit

The reference is here, it has size() method identical to std::vector and uses [square brackets] for element access. That should cover most tasks.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-01-19 13:01:40 -0600 )edit

@PeteBlackerThe3rd, really appreciated, that looks exactly what I need!

Hypomania gravatar image Hypomania  ( 2019-01-19 13:26:41 -0600 )edit

Question Tools

1 follower


Asked: 2019-01-19 08:55:46 -0600

Seen: 1,380 times

Last updated: Jan 19 '19