Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-11-12 22:15:54


On Monday 12 November 2001 10:38 pm, you wrote:
> Hi,
>
> For most applications, one wouldn't care that the constructor of
> boost::function<> might throw an exception. In my case, however, I need to
> ensure that it won't. I think I understand why dynamic allocation is
> neccessary to boost::function, but I think there's a wide class of
> applications for which it shouldn't be neccessary. I'm thinking of
> operations which need to use a function object, but don't need to store it
> (think for example of a suite of algorithms operating on a particular type
> of iterator).
>
> How far is boost::function from being able to provide this sort of
> functionality?

Not far. As I see it, there are 3 types of function objects that don't need
memory allocation within Boost.Function:
        - function pointers
        - unbound pointers to member functions
        - "stateless" function objects

Boost.Function allocates no memory for the first of these (function
pointers), and the other two are on my TODO list. The last one of these seems
to be what you want ("stateless" function objects), and would require an
additional type trait is_stateless -- which could be described as is_empty &&
has_trivial_constructor && has_trivial_copy && has_trivial_assign &&
has_trivial_destructor.

An alternative that would work right now would be to use a custom allocator.

        Doug


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