Hi Peter, Peter Dimov wrote: <snip>
Four copies - I had hoped to only see a single copy. Logically, there doesn't seem to be a need for more than one copy. Is there an implementation issue that requires this many copies?
Not really, but eliminating the unnecessary copies is (relatively) hard, at least with the current code base (it has been developed with portability in mind and supports VC6, among others). The specification requires one copy. One more is almost unavoidable. The other two can be eliminated, in theory. But...
Ok, thanks. Out of interest, is there a simple explanation for why one more is almost unavoidable. <snip>
... please note that the copies occur at bind time. In a typical scenario you bind once and call O(N) times (or bind and store in a function<> with the associated dynamic memory allocation), so this isn't usually a problem. And, as others have pointed out, there's always ref(). ;-)
Yes I understand. I guess I'm not using bind typically ;-)
FYI and for those suggesting boost::ref, the actual case is using bind
for message passing between threads. I have a polymorphic wrapper for
bind something like this:
class bind_wrapper
{
public:
virtual void execute() = 0;
};
template <typename binder_t>
class bind_wrapper_impl : public bind_wrapper
{
public:
bind_wrapper_impl(const binder_t &binder_a)
: binder_m(binder_a)
{
}
virtual void execute()
{
binder_m();
}
private:
binder_t binder_m;
};
template <typename binder_t>
std::auto_ptr