On Thu, Jun 27, 2019, 7:09 PM Gavin Lambert via Boost
On 28/06/2019 07:57, David Sankel wrote:
If a class uses PIMPL and does a move, isn't that just a pointer swap which cannot throw? Or would that be implemented as another allocation in the moved-from class? I can't imagine why.
Move assignment is fine. Move construction is where allocation would need to happen so the "moved from" object stays in a valid state.
I'm not sure why. Both unique_ptr and shared_ptr (one of which is usually used as the "guts" of pimpl, depending on whether you want it to be reference-semantics-copyable or not) do not need to allocate on move construction (and are noexcept) -- they just leave the moved-from object empty.
Many would prefer their PIMPL classes to not have an artificial empty/partially formed state because of the increased semantic complexity that implies.