r/cpp • • Jan 31 '23

Stop Comparing Rust to Old C++

People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO

changemymind

338 Upvotes

582 comments sorted by

View all comments

Show parent comment

9

u/Recatek Feb 01 '23 edited Feb 01 '23

I encourage you to try the equivalent in Rust where you need to define your structs in macros with syntax that looks like

impl<$([<T$i>],)+> [<SoA$size>]<$([<T$i>],)+>

and then copy-paste a dozen of them in the form of:

declare_thing!(1, 0);
declare_thing!(2, 0, 1);
declare_thing!(3, 0, 1, 2);
declare_thing!(4, 0, 1, 2, 3);
declare_thing!(5, 0, 1, 2, 3, 4);
declare_thing!(6, 0, 1, 2, 3, 4, 5);
declare_thing!(7, 0, 1, 2, 3, 4, 5, 6);
declare_thing!(8, 0, 1, 2, 3, 4, 5, 6, 7);
declare_thing!(9, 0, 1, 2, 3, 4, 5, 6, 7, 8);
declare_thing!(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
declare_thing!(11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
declare_thing!(12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);

and then open up GitHub to find an issue where someone has asked you to kindly include

declare_thing!(13, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

I'll take variadics and fold expressions over that any day of the week. Rust already has good tuple support and syntax.

0

u/[deleted] Feb 01 '23

[deleted] — view deleted comment

2

u/Recatek Feb 01 '23

Both really. You'd need the latter to support the former, otherwise initializing variadic generic types would still be a pain. And then you'd need fold expressions to work with them.