Boost logo

Boost :

From: Julien Blanc (julien.blanc_at_[hidden])
Date: 2023-12-05 09:17:19


Le 2023-12-01 15:42, Andrey Semashev via Boost a écrit :

> Besides, there isn't an efficient way to prevent the user from this
> issue. Sure, I could specialize scope guards on std::function (at the
> cost of including <functional>, which would penalize every user, even
> those who never wanted to use std::function to begin with), but it
> doesn't prevent users from using boost::function or any other
> equivalent.

Actually, i was thinking of something far more radical. Something like
requiring is_trivially_copyable<F>. From a theoric point of a view, it
is clearly not the correct trait, but there's just no way to tell the
compiler that we need the initializing expression to be noexcept. In
practice, it does the job quite well at preventing bad usage, while
still preventing not too much (in our code base, i can't recall of any
case where this caused us trouble).

>> Thanks, this is the kind of definitive answer i was looking for. I
>> could
>> unfortunately not find it in the documentation, though. I think it
>> deserves to be added (if it is present, then it probably should be
>> emphasized more).
>
> It is part of the scope guard reference documentation, e.g.:
>
> https://lastique.github.io/scope/libs/scope/doc/html/boost/scope/scope_exit.html#idm3835-bb

Thanks. Then i'll go for "it should be emphasized more". I was expecting
to find such guarantee in the feature list of the library.

Regards,

Julien


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