Boost logo

Boost :

From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2007-06-06 22:06:48


I wrote an implementation which removes the Allocator parameter of
boost::function:

http://www.revergestudios.com/boost-function/

All tests pass on msvc 7.1, 8.0, and gcc 3.4.4 (I had to modify the
allocator test.) To try my implementation, you'll need the rest of the
boost::function files from CVS HEAD.

Allocators are supported as an argument to the following boost::function
constructor:

template<typename Functor,typename Allocator>
function(Functor f, Allocator a);

A copy of the passed allocator is stored in the boost::function object, the
same way it's done in shared_ptr.

Notes:

1) As in the current official boost::function implementation, the allocator
is only used if the boost::function object is initialized with a function
object which does not fit in a "small" static buffer.

2) When a function object that can not use the small object optimization is
assigned (by operator=) to an existing boost::function object, the
boost::function object will not have an allocator and will use new/delete.
To allow users to supply an allocator in an assignment operation, I added a
new member function:

template<typename Functor,typename Allocator>
void assign(Functor f, Allocator a);

Emil Dotchevski

----- Original Message -----
From: "Douglas Gregor" <doug.gregor_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, June 05, 2007 10:46 AM
Subject: Re: [boost] [function] allocator template parameter question

>
> On Jun 5, 2007, at 12:42 PM, Emil Dotchevski wrote:
>
>>
>>> 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.
>> Perhaps if the allocator it's moved to the constructor, the
>> committee would accept it? :)
>
> Since shared_ptr already has this functionality in its constructor,
> they may accept it. You could certainly write a short proposal to the
> C++ committee...
>
>>> <snip>> 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?
>> OK, I'll give it a shot, and I'll let you know how it goes.
>
> Great!
>
> - Doug
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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