Boost logo

Boost Users :

Subject: Re: [Boost-users] Why does boost thread copy a functor?
From: Chris Cleeland (chris.cleeland_at_[hidden])
Date: 2012-01-16 21:16:05


Lars,

On Sun, Jan 15, 2012 at 8:01 PM, Lars Viklund <zao_at_[hidden]> wrote:
> Please do not top post, the list guidelines encourage bottom posting.

Apologies; I was on my phone which makes editing difficult.

> Your wrapper does not seem to follow the rule of three:
> If a class defines one of the following it should probably explicitly
> define all three:
> * destructor
> * copy constructor
> * assignment operator
>
> Your wrapper type does not seem to have provided adequate
> implementations for the cctor and op=, or has not prevented the
> synthesised ones from existing.

I'll review the wrapper in light of your comments. Thanks!

> Another alternative is that you can hold your state in the Task by
> reference or smart pointer, such that if it's copied, the guts still
> refer to the correct state.

Good suggestion, but that doesn't solve the situation where I wanted
the actual object to be shared.

While I understand the rationale now (thanks to your excellent
explanation), I will also point out that I am not alone in my
misunderstanding of the interface. I discussed the issue with a few
colleagues and asked what they would expect to happen, and they all
had similar expectations to mine (that the functor was not copied).
The commonality of misunderstanding is what prompted my suggestion
that the copying of the argument be more explicit.

I truly appreciate the help and apologize for the top-posting.

-- 
Chris Cleeland

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net