Boost logo

Boost :

Subject: Re: [boost] [function] function wrapping with no exception safetyguarantee
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-10-07 21:47:11


On Thu, Oct 7, 2010 at 7:22 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
> Daniel Walker wrote:
>
>> void do_stuff(boost::function<int(int)> f)
>> {
>>   // ...
>>   if(f) {
>>       // Remove the exception safety guarantee for this block.
>>       boost::unsafe_function<int(int)> g = f;
>>       for(int i = 0; i < INT_MAX; ++i)
>>           g(i);
>>   }
>>   // ...
>> }
>
> This example implies that unsafe_function is inherently more efficient, but
> this need not be so. An empty function may point to throw_bad_function_call
> instead of NULL.

That is what I recommended in another thread, that instead of an empty
function pointer it points to a static global function that asserts or
throws or something, possibly user-definable. So a
default-constructed function should always point to that static
function or so.


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