News for hackers. Stuff that matters.
Re:When zero cost abstractions aren't zero cost by lenkite on Monday August 09, 2021 @11:14PM (#28124822)
Why did a Rust defect become such a diatribe on C++ ? As far as I am aware, using a typedef/using type does not slow down zero-based initialisation of primitive types in C++. (last time I checked a few years ago - will apologise if this has changed).
Re:When zero cost abstractions aren't zero cost by tialaramex on Monday August 09, 2021 @11:34PM (#28124912)
Rust wrapper types aren't like C++ typedef. If you just want an alias for the u8 type in Rust, you get the exact same performance:

type Tiny = u8;

The compiler knows a "Tiny" is just a u8 anyway and exactly the same code is produced.

The wrapper type is a distinct type, which is why you'd want one because it can have different properties from whatever it's wrapping.

Re:When zero cost abstractions aren't zero cost by jcranberry on Tuesday August 10, 2021 @04:12PM (#28133712)
The newtype is analogous to what I've heard called a "strong typedef" in c++ lingo.

Using/typedef declarations in c++ only introduce a new name, not a new type.

Re:When zero cost abstractions aren't zero cost by yyyk on Monday August 09, 2021 @11:17PM (#28124839)
Sorry, got bit a bit too much by C++ templates and a few other things. Rust views itself as a successor language, and I wouldn't like it to make the same mistakes.