|
Boost : |
Subject: Re: [boost] [function] function wrapping with no exceptionsafetyguarantee
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2010-10-25 15:19:35
On Fri, Oct 22, 2010 at 5:01 PM, Nevin Liber <nevin_at_[hidden]> wrote:
> On 22 October 2010 14:09, Daniel Walker <daniel.j.walker_at_[hidden]> wrote:
>> To make the example
>> portable, you need to add a destructor to S1.
>
> Why?
This is to force function_base::has_trivial_copy_and_destroy() to
evaluate to false on line 971 of function_template.hpp. (Different
compilers handle default destructors differently, so to force the same
behavior on all platforms, you need to define a destructor.) The
target function object is only cloned if it has a copy-constructor or
destructor, since cloning is not necessary when swapping stateless
function objects. Good question.
>
>> struct S1 {
>> ~S1() {}
>> void operator()() {}
>> void* operator new(std::size_t, void* p)
>> {
>> // throw on third alloc
>> if(++i == 3)
>> throw std::bad_alloc();
>> return p = ::new S1();
>> }
>> };
I just realized there is another technical error in my example, though
it doesn't affect the behavior being demonstrated. That operator new
is an in-place new, of course, so the return should be:
return ::operator new (s, p);
Thanks!
Daniel Walker
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk