Hacker News new | ask | show | jobs
by Kenji 1467 days ago
Have you ever wondered what a "moved-from" object [0] in C++ contains? In Rust, such objects are inaccessible due to enforcement of the compiler. In C++, they are accessible. Have you ever wondered what performance implications that has? Have you looked into what the C++ standard tells us about "moved-from" STL objects, what state they are in?

[0] e.g. `b = std::move(a)`, what is in `a` now?

1 comments

There are good use cases for requiring the moved object to still be valid and accessible, such as when memory lifetimes are decoupled from object lifetimes. It enables some optimizations. The specific state depends on the design of the type and its use case.