On Tue, Aug 3, 2021 at 9:03 AM language.lawyer--- via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On 03/08/2021 15:22, Andrey Semashev via Std-Proposals wrote:
> On 8/3/21 3:08 PM, Jens Maurer via Std-Proposals wrote:
>> On 03/08/2021 11.46, Baruch Burstein via Std-Proposals wrote:
>>> Hi.
>>> Why is there no generic scope guard in the standard library?
>>> I am sure there must have been such a proposal before, probably with an explanation of why it was not accepted, but I couldn't find it.
>> Try std::unique_ptr with a custom deleter.
> This only works for pointers.

unique_ptr can be used with non-pointers

Oddly enough, both of those SO links are from people asking "Why can't I use unique_ptr on non-pointers?" and people in the answers pointing out that unique_ptr can be used only with pointers (that is, with types that satisfy the NullablePointer requirements). Notably, if your type isn't convertible-from `nullptr`, then it can't be wrapped in a unique_ptr (because unique_ptr works only with pointers).

However, for a generic scope guard, I recommend `Auto`: