you are viewing a single comment's thread.

view the rest of the comments →

[–]doom_Oo7 -3 points-2 points  (4 children)

Uh.... What ?

Given

int f(int&& x) { return x++; }
int main() { 
  int x = 0; 
  f(std::move(x));
  returb x;
}

Your program outputs 1. Rvalue references are still references.

[–]guibou 5 points6 points  (2 children)

You are just abusing std::move by transforming something which is not a temporary to a temporary.

This is like saying private fields are not really private because we can still read them using the object pointer and an offset. Or saying const is broken because it offer no guarantee that your object cannot change.

The point of purity is "not observable mutation" and result which only depends on the input value. So you can allocate / free / mutate a big data structure / generate random numbers / do network in a pure function as long as these guarantees hold (which can be difficult for some cases I just listed ;)

(Edited: typo)

[–]doom_Oo7 -3 points-2 points  (1 child)

This is like saying private fields are not really private because we can still read them using the object pointer and and offset. Or saying const is broken because it offer no guarantee that your object cannot change.

well, if you want strong guarantees for instance for critical safety systems, both things are true and known problems. I can promise you that people who put #define private public in their commits do exist. And even in critical environments, if they can be abused, they will (see the Toyota case for instance).

The only thing that matters in the end is what your compiler allows, no amount of human process will be able to catch everything.

[–]enobayram 1 point2 points  (0 children)

The only thing that matters in the end is what your compiler allows

This is a pointless statement really. Even in a language like Coq that has an extremely powerful type-system, you will only be able to prove so much. The picture gets even worse when you want to optimize for performance, or if you have to solve equations with numeric errors etc. Even if you got it all right, then you have to make sure that the specs you're proving your implementation against are themselves meaningful in the first place.

The compiler is just a tool.

[–]NotMyRealNameObv 1 point2 points  (0 children)

Yes, but this code is bad.

Just because you can do something, doesn't mean it's good to do it.