Boost logo

Boost :

Subject: Re: [boost] Design conventions; passing functors
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-11-15 17:14:37


----- Original Message -----
From: "Joachim Faulhaber" <afojgo_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, November 06, 2008 6:28 PM
Subject: Re: [boost] Design conventions; passing functors

>
> 2008/11/6 Steven Watanabe <watanabesj_at_[hidden]>:

>>> I do not really understand this convention and feel some
>>> resistance to follow it. In addition the call by value
>>> implementation can (and will) lead to heavy inefficiency
>>> by unaware usage of fat functors.
>>
>> The assumption is that function objects are not fat.
>> If you have a large function object, it is always
>> possible to create another function object that just
>> stores a reference to the original function object.

Is not this the role of boost::ref?

> Unfortunately the assumption can not be that all programmers
> are always aware of the many c++ intricacies.
>
> There's a rule stated by Scott Meyers in one of his books:
> "Make your classes easy to use correctly and difficult to
> use incorrectly."

If the parameter do a copy is is very difficult to use incorrectly, either you function is CopyConstructible and works, or if not it not compiles. If the functor is heavy to copy it is up to the functor designer to forbid copy construction. Optionaly the Functor can implement move semantics, but this is not absolutely needed. In any case to can wrap it with boost::ref.

Am I missing something basic?

Vicente


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