On Mon, Nov 7, 2011 at 3:15 PM, Peter Dimov <pdimov@pdimov.com> wrote:
Robert Jones wrote:
Thanks Gents - The phrasing of my question was hopelessly lax: I appreciate in the
general case why one might choose to use a functor rather than a function as a callable
object, what I didn't grasp (and there may be nothing to grasp), was why this (from the
shared_ptr docs)

struct null_deleter
{
   void operator()(void const *) const
   {
   }
};

Is implemented as a functor rather than a function.

There's nothing to grasp. The only difference is that sizeof( null_deleter ) is 1, whereas sizeof the function would be 4 or 8, but due to alignment, they both will take up the same space in the actual control block, so it doesn't matter one bit. Using a functor here is purely coding style - the size difference, the fact that operator() would be inlined, the ability to template operator() could all have been relevant in another context.


Thank you Peter - your confirmation is appreciated.

- Rob.