C++ Logo

std-discussion

Advanced search

Re: Some feedback on scope guards

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 14 Apr 2023 15:50:04 +0300
On Fri, 14 Apr 2023 at 15:44, Edward Catmur via Std-Discussion
<std-discussion_at_[hidden]> wrote:

> If you allow tuple, then you have to allow vector, and since a vector can be moved without moving its elements you then have the problem of (success/failure) scope guards being destroyed from a scope other than the one they were constructed in.

Then don't do such moves. We have various book entries about "how to
prevent dynamic allocation of objects of your type"
and "how to prevent objects of your type being used as subobjects",
and they're always weird, never work well, and are
always wrong to begin with. If we are in a tar pit of a design that
suggests such limitations to be necessary, we need
to climb out of it, and fast.

Received on 2023-04-14 12:50:16