News for hackers. Stuff that matters.
Re:Embracing Modern C++ Safely, Book Review by tialaramex on Monday May 30, 2022 @07:29PM (#31564707)
Hmm. From Rust 1.0 in 2015 Rust provides natural for syntax which let you write:

for clown in clowns

This is pretty different from how C++ iterators work:

for (auto clown = clowns.begin(); clown != clowns.end(); ++clown)

So, to "try to compete" we'd expect Rust to adopt the C++ features here right? But instead, in C++ 20 now you can write:

for (auto clown : clowns)

Notice that, as so often, to get here C++ has to add layers of hacks. In Rust clowns is simply any type that implements IntoIterator. That's all, this feature is just syntax sugar and you can implement it yourself calling std::iter::IntoIterator::into_iter(clowns) and then looping over the resulting iterator -- but C++ has not only explicit handling for the range feature here, it also needs two extra special cases to handle the broken C++ built-in array type and the C++ initialiser structures so that these both do what you expect.

So, five years later, and with extra hacks, C++ gives you the same feature as Rust, and we are to believe that C++ isn't the one trying to compete?

Re:Embracing Modern C++ Safely, Book Review by Kranar on Monday May 30, 2022 @07:56PM (#31564855)
None of what you're saying is true though.

Range based for loops were introduced in C++11 (technically C++11 was published in 2011, but almost all compilers supported this way back in 2008-2009) and it's also nothing more than syntactic sugar. In order to provide support for a type T you need the following functions, which can be free functions or member functions:

begin(T&)

end(T&)

++(decltype(begin(T&)))

The only hack I can think of related to your post is that if T is an array, it uses the free functions std::begin and std::end which are overloaded to work with C arrays.

Re:Embracing Modern C++ Safely, Book Review by staticassertion on Monday May 30, 2022 @08:00PM (#31564871)
It's not really competing. New rust features often get compared to existing C++ features. Also, I'm sure many people in C++-land are looking at rust and wondering which bits they like can be brought over.
Re:Embracing Modern C++ Safely, Book Review by ncmncm on Monday May 30, 2022 @08:24PM (#31564996)
There is plenty that Rust has not got.
Re:Embracing Modern C++ Safely, Book Review by oncewas on Monday May 30, 2022 @09:41PM (#31565358)
That's actually a motivating reason for why people and companys tend to like Rust . many people transition to rust because c++ has become very bloated, complex, and the rules for what happens in the language can be more complicated than x86 assembly...
Re:Embracing Modern C++ Safely, Book Review by staticassertion on Monday May 30, 2022 @10:58PM (#31565704)
I wasn't implying otherwise. As I said, there's plenty of Rust that is inspired by C++. A lot of the 'const fn' stuff is talked about in the context of constexpr, for example. A lot of the const generics as well.
Re:Embracing Modern C++ Safely, Book Review by atq2119 on Monday May 30, 2022 @07:42PM (#31564782)
Range for loops are in C++11, 4 years earlier than Rust 1.0.
Re:Embracing Modern C++ Safely, Book Review by tialaramex on Monday May 30, 2022 @10:33PM (#31565578)
Thanks, I had this wrong because I was thinking of the concrete ranges (from C++ 20) instead.
Re:Embracing Modern C++ Safely, Book Review by Rexxar on Monday May 30, 2022 @08:29PM (#31565018)
And c++11 was very late, so it was already a very old idea at this point.
Re:Embracing Modern C++ Safely, Book Review by ncmncm on Monday May 30, 2022 @08:22PM (#31564988)
Ignorance does not make an authority.

Little of what "tialaramex" writes is correct, and none of substance.

Re:Embracing Modern C++ Safely, Book Review by tialaramex on Monday May 30, 2022 @10:38PM (#31565599)
This was wrong (and I was away long enough that the correction window expired), as I've acknowledged elsewhere, but I would suggest that factually the numbers don't match your claim at all.