2 ms·
std::move is lower level than that. It is a primitive that you can use to implement whatever lifecycle semantics you want. To see what I mean, in the examples
by hedora 7y ago
std::move is lower level than that. It is a primitive that you can use to implement whatever lifecycle semantics you want.
To see what I mean, in the examples in the article, the author has to tell the compiler all sorts of things that are hard to infer. For example, the object comes into being in the “unconsumed” state (what if I instantiate it with a nullptr? Can I even do that?), and a prerequisite to dereferencing it is that it is “unconsumed”.
It is plausible that there would someday be a set(foo&&) method that had “unconsumed, consumed, unknown” as a prerequisite, and always brought the type into the “unconsumed” state.
In practice, you shouldn’t be spraying these annotations all over a code base. They should be in library methods that are reused frequently, so that you get a lot of static analysis benefit from a small number of manual annotations.