Using unique_ptr, while maybe possible, is overcomplicated and has a larger then needed memory footprint if not using any pointer, just a callable. i.e., try using unique_ptr to just call this on scope exit:

[](){ printf("hi!\n"); }

On Tue, Aug 3, 2021 at 4:03 PM via Std-Proposals <> 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
Std-Proposals mailing list