ROS 2 and C++20

Rust is “fast, reliable, productive: pick three”… golang feels like a toy, no proper sum types or generics and a gc, bleh.

You’re right. There’s nothing preventing me from using C++20. Except I have to specify usage of it in every package. And then remember to remove it when it becomes the ros2 default. I’m sure there are clean ways to do. I’m just wondering what the ros2 roadmap is which doesn’t look like has been determined.

The ros2 API sometimes has breaking changes in a new distro. I have had to fix compilation errors when switching to a new distro. So yes, in theory, the API can leave existing ones in place but that is not the case in practice. In this case, it does force change on everyone. On the other hand, a C++ version forces change under the cover but as an end user you won’t even notice it - you just recompile your code without having to change anything. You’re going to recompile anyway when switching to a new distro that supports the new C++ version and you’ll be fixing compile errors due to API changes not C++ version changes.

I’m not sure what the argument is against this other than the work it takes to qualify the ros2 core on a new version which I admit may not be trivial. Anyway, my original question was answered. It will happen at some time, but it is unclear when. Till then I have the option of using C++20 on my own packages by specifying the version to the compiler.

1 Like

Technically I think you should specify the version of C++ you use in your cmake even if ROS has a default. That way if someone tries building it on a system that is not the ros buildfarm that has different defaults it will still work.

Not sure where the ROS default is specified. Must be somewhere in ament. I am curious.

I can see your point about non-ROS-specific packages. For ROS packages, I’m not sure I would want to have the C++ version in every cmake. It’s something else that needs to be maintained. I guess I could be convinced otherwise.

I don’t believe a ros2 default is specified in any central place. Individual packages specify their C++ standard version in CMake, and we say that the “ros2 core is on X version” when all (any?) packages under https://github.com/ros2/variants/blob/master/ros_core/package.xml now specify that version. (could be wrong on that but it’s my understanding)

1 Like

Yep, you have it exactly correct.

2 Likes

Hmm. Good to know. For some reason, I got it into my head that C++17 features were available to me when I switched to Galactic. But it’s because my compiler defaulted to C++17.

This also seems to imply that all packages should probably specify the C++ version in the cmake as @tylerweaver suggested instead of relying on the compiler default.

If I get it correctly, C++ is forward-compatible up to some very obscure things like auto_ptr. So if you write a package working with the default compiler of an older ROS distro, it should also work with newer ROS distros. Up to those obscure things, of course. So it doesn’t seem to me very important to add the standard declarations. They’re one more thing to maintain. It really seems to me the best choice depends on your development process and the number of C++ features you use.

REP 2000 specifies the minimum C++ version that each ROS distribution is required to work with. This is, in general, derived from the combination of the C++ version available in the G++ compiler on the version of Ubuntu that distribution is targetting, and the need to ensure users who work in more restricted environments (e.g. safety-critical systems and embedded systems) will be able to work with the source code.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.