Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2023-11-30 18:26:27


On 11/30/23 19:02, Peter Dimov via Boost wrote:
> 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.

What I meant is something like this won't work:

https://godbolt.org/z/hczoP4WMx

And if you're suggesting to define some magic placeholder type that can
be used as Def and automatically converts to R then that looks like a
more contrived usage to me than just defining resource traits.


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