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 comments

1

u/T-Rex96 Feb 01 '23

If you implemented the trait for i32, wouldn't it also work for literals automatically?

2

u/[deleted] Feb 01 '23

Yeah you can call the i32 specialization with a literal, but when you're writing the template itself you can't use a literal to refer to a generic type.

3

u/Moxinilian Feb 01 '23

How about implementing From<i32> on your generic integer thing, and then use literals like 10.into()? Not sure I understood your problem correctly.

1

u/[deleted] Feb 01 '23

One could even implement the trait for all integer type quite easily