
On Jun 4, 2007, at 10:57 PM, Emil Dotchevski wrote:
One important advantage of using boost::function is that it acts like a function pointer, reducing physical coupling between compilation units. This is very much like shared_ptr.
A nice feature of shared_ptr is that it has a single template parameter, T, even though diferent instances of shared_ptr<T> can use different allocators.
When using boost::function, one can also provide an allocator, but unlike shared_ptr, the allocator is a default parameter of the boost::function class template.
Is there a reason why this is necessary? Can't boost::function use similar technique to the one employed by shared_ptr to avoid the need for this second template parameter?
You know, I never even thought about adding it. I didn't know about the shared_ptr technique when I put the allocator into boost::function, and after the C++ committee removed the allocator I didn't think about it any more. The biggest issue with moving the allocator into the constructor (like shared_ptr) is that boost::function doesn't know what type it is going to be interacting with... shared_ptr<T> knows it's 'T', function does not. However, I think we can work around this issue. It certainly would be better to have the allocator supplied in the constructor. I don't know when I would have time to implement this, although I would certainly consider adding this functionality to Boost's "function". Might you be interested in implementing it? - Doug