Skip to content

Add initializer_list support to Buffer class - #2

Open
karsten-nvidia wants to merge 3 commits into
nvcyc:rolling-native-bufferfrom
karsten-nvidia:add-initializer-list-support
Open

karsten-nvidia wants to merge 3 commits into
nvcyc:rolling-native-bufferfrom
karsten-nvidia:add-initializer-list-support

Conversation

@karsten-nvidia

Copy link
Copy Markdown

Generated code tries to initialize Buffer fields using brace-enclosed initializer lists, but Buffer class was missing the necessary constructor and assignment operator.

Added:

  • #include <initializer_list> header
  • Constructor: Buffer(std::initializer_list<T>)
  • Assignment operator: operator=(std::initializer_list<T>)

Both operations create/use CPU backend and delegate to std::vector::assign() method.

Fixes: Compilation error in test_msgs and other generated message code that uses default values for Buffer fields.

Testing:

  • test_msgs package now builds successfully
  • All generated code compiles without errors

Related:

🤖 Generated with Claude Code

nvcyc and others added 3 commits February 3, 2026 22:58
Replace deprecated ament_target_dependencies() with modern CMake
target_link_libraries() using namespace targets (rmw::rmw,
rosidl_runtime_cpp::rosidl_runtime_cpp, pluginlib::pluginlib).

This pattern aligns with other modern ROS 2 packages (pluginlib,
class_loader) and resolves build issues when ament_cmake is used
without ament_cmake_ros.

Changes:
- Line 33: target_link_libraries(PUBLIC) instead of ament_target_dependencies()
- Line 73: Same pattern for test target

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Generated code tries to initialize Buffer fields using brace-enclosed
initializer lists, but Buffer class was missing the necessary
constructor and assignment operator.

Added:
- Constructor: Buffer(std::initializer_list<T>)
- Assignment operator: operator=(std::initializer_list<T>)

Both operations create/use CPU backend and delegate to std::vector's
assign() method.

Fixes compilation error in test_msgs and other generated message code.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@nvcyc
nvcyc force-pushed the rolling-native-buffer branch from c38418d to e6dff7d Compare February 6, 2026 19:37
@nvcyc
nvcyc force-pushed the rolling-native-buffer branch from c874df7 to 980eea0 Compare March 13, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants