Add std::vector compatible swap() API to rosidl::Buffer#959
Open
Add std::vector compatible swap() API to rosidl::Buffer#959
Conversation
Signed-off-by: CY Chen <cyc@nvidia.com>
MiguelCompany
suggested changes
Apr 22, 2026
| EXPECT_EQ(2, buffers[1][0]); | ||
| EXPECT_EQ(3, buffers[2][0]); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
I would add tests checking that calling swap on non-CPU buffers throws an exception.
|
Confirming that this fixes the problem reported in ros-perception/perception_pcl#529. But note that even with this change, some packages would still need to be updated. Besides PCL, I discovered wep21/bag2_to_image#8, where the compatibility with OpenCV was broken. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the missing
swap()APIs torosidl::Bufferso that it remains a true drop-in replacement forstd::vectorin CPU-backed message fields.Specifically the following functions are added for
rosidl::Buffer(src/ros2/rosidl/rosidl_buffer/include/rosidl_buffer/buffer.hpp):swap(Buffer &)swap(std::vector<T, Allocator> &)rosidl::swap(Buffer&, Buffer&)rosidl::swap(Buffer&, std::vector&)rosidl::swap(std::vector&, Buffer&)Is this user-facing behavior change?
Yes.
rosidl::Buffernow supports all theswapforms thatstd::vectordoes, including the cross-type cases withstd::vector.Additional Information
This is to fix the issue discovered from ros-perception/perception_pcl#529.