Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2023-11-30 16:02:00


Andrey Semashev wrote:
> >>> I think a similar utility would be more useful in form of a class
> >> template,
> >>> for example:
> >>>
> >>> resource<HANDLE, INVALID_HANDLE_VALUE, ::CloseHandle>
> windows_handle;
> >>> resource<SDL_Window*, nullptr, ::SDL_DestroyWindow>
> sdl_window_handle;

That's

template<class R, auto Def, auto Del> class resource;

> This would also prohibit resource types with non-constexpr constructors,
> as well as non-default-constructible resources. I don't like this tradeoff.

It doesn't. The two operations required from R are construction from Def
and comparing to Def.

https://godbolt.org/z/h7z3qGzvs

Note that the type of Def doesn't have to be R.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk