About 28 years ago, I figured out that I’m just not smart enough to use C++. There are so many foot guns and so much rampant complexity that I can’t keep it all straight. I crave simplicity and it always felt like C++ craved the opposite.
C++ std::move doesn't move anything: A deep dive into Value Categories
51–60 of 220 posts
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#52Earlier quoted context omitted.
It is absolutely knowable statically if ownership will be taken. It's not necessarily very easy to do so, but the decision is 100% up to the compiler, as part of overload resolution and optimization choices (like the NRVO analysis that the article mentions). Since ownership is an inherently static concept, it doesn't even make sense to think about "runtime ownership".
I don't understand the downvoted here. Either the compiler emits the code to call a move constructor or it doesn't.
Code can be emitted but never executed.
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#53Earlier quoted context omitted.
TFA explains how std::move is tricky to use and this is not a feature reserved for library writers
Of course it is not reserved for library writers - nothing is. But it is not a feature that application writers should worry about overmuch.
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#54The design lesson I draw from this is that pursing a 100% general solution to a real problem is often worse than accepting a crude solution which covers the most important cases.
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#55https://news.ycombinator.com/item?id=45799157 (87 comments)
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#56About 28 years ago, I figured out that I’m just not smart enough to use C++. There are so many foot guns and so much rampant complexity that I can’t keep it all straight. I crave simplicity and it always felt like C++ craved the opposite.
Even languages that have tried to fast-follow and disrupt C++ end up looking a lot like C++. There is an irreducible complexity.
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#57Earlier quoted context omitted.
The only thing that is statically known here is that you’re wrong. The function I posted only moves its parameter half the time, at random. You may want to treat it as moved-from either way, but factually that’s just not what is happening.
This is like trying to defend that you can't statically know the result of 1 + 2 because: void foo() { std::random_device rdev {}; auto dist = std::uniform_int_distribution (0, 1); if (dist(rdev)) { int res = 1 + 2; } } I can tell you for sure that the result of 1 + 2 will be 3.
It is completely unlike that. tsimionescu is asserting that they can always know statically whether `foo` will move its parameter. The function I provided is a counter-example to that assertion.
Of course the branch body always moves, that's what it's there for. That has no bearing on the argument.
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#58Earlier quoted context omitted.
Std move doesn’t move ownership. It simply casts into something that could have its ownership taken. Whether or not that actually happens is impossible to identify statically and the value after ownership is consumed is unspecified - sometimes it’s UB to access the value again, sometimes it’s not.
After moving a value, it needs to remain in a "valid but unspecified state". How do you mean accessing a valid object is UB?
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#59> So the standard library plays it safe: if your move constructor might throw (because you didn’t mark it noexcept), containers just copy everything instead. That “optimization” you thought you were getting? It’s not happening. This is a bit of a footgun and clang-tidy has a check for it: performance-noexcept-move-constructor. However, I don't think it's enabled by default!
Most sensible Compiler flags aren't enabled by default... I keep a list of arguments for gcc to make things better, but even then you'll also wanna use a static analysis tool like clang-tidy
Re: C++ std::move doesn't move anything: A deep dive into Value Categories
#60Whoever wrote that definition should have a thing or two to learn from Rust. Different language I know, but it proves that it wasn't needed to cause so much confussion and collectively so much time and performance lost.
Also, who writes rules like that and ends the day satisfied with the result? It seems unlikely to feel content with leaving huge footguns and being happy to push the Publish button. I'd rather not ship the feature than doing a half-assed work at it. Comparing attitudes on language development and additions, it makes me appreciate more the way it's done for the Go lang, even though it also has its warts and all.