invariants

What constitutes a valid state for a “moved from” object in C++11?

与世无争的帅哥 提交于 2019-11-26 10:34:21
I've been trying to wrap my head around how move semantics in C++11 are supposed to work, and I'm having a good deal of trouble understanding what conditions a moved-from object needs to satisfy. Looking at the answer here doesn't really resolve my question, because can't see how to apply it to pimpl objects in a sensible way, despite arguments that move semantics are perfect for pimpls . The easiest illustration of my problem involves the pimpl idiom, like so: class Foo { std::unique_ptr<FooImpl> impl_; public: // Inlining FooImpl's constructors for brevity's sake; otherwise it // defeats the

What constitutes a valid state for a “moved from” object in C++11?

◇◆丶佛笑我妖孽 提交于 2019-11-26 01:53:49
问题 I\'ve been trying to wrap my head around how move semantics in C++11 are supposed to work, and I\'m having a good deal of trouble understanding what conditions a moved-from object needs to satisfy. Looking at the answer here doesn\'t really resolve my question, because can\'t see how to apply it to pimpl objects in a sensible way, despite arguments that move semantics are perfect for pimpls. The easiest illustration of my problem involves the pimpl idiom, like so: class Foo { std::unique_ptr