Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rosidl_generator_cpp] Generate constructors that take all msg members as arguments #842

Open
jmachowinski opened this issue Nov 26, 2024 · 4 comments
Assignees

Comments

@jmachowinski
Copy link

Feature request

Feature description

It would be nice, if for every msg a constructor would be generated, that takes all msg members as arguments.
There would be some positive effects from this:

  • Compile time check if msg was modified
  • Makes it harder to 'forget' to initialize a member
  • Enforces RVO

Implementation considerations

Would slightly raise compile times
Default constructors must stay for compability

@alsora
Copy link

alsora commented Dec 8, 2024

FYI, see this old discussion on the topic: #749
The purpose was different though.

In that case, we wanted to avoid to pay the cost for a default initialization.
The solution we discussed in that case was based on the use of aggregate initialization with designated initializers, which requires C++ 20 (currently ROS uses C++ 17).

@jmachowinski
Copy link
Author

@clalancette My college had a good point to add to the discussion: Using constructors with arguments is 'The C++ way' of initializing objects. Not supporting it is kind of odd.

@fujitatomoya
Copy link

I do not have any objections for this feature. I do not quite follow the discussion during today's PMC meeting, what could be the downside of this feature?

@jmachowinski
Copy link
Author

There were two points against it:

  • Adding yet another method to initialize a message.
  • You would have a silent error if you would switch two members in your message of the same type.

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

No branches or pull requests

3 participants