Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-11-14 23:50:20

On Wednesday 14 November 2001 06:00 pm, you wrote:
> You can call handle_exception with an arbitrary function object that has a
> "signature" PyObject* f(), and it will work without allocating any memory
> on the heap. The bulk of the code (in handle_exception_impl) is not
> repeated for each different function object type. handle_exception_impl
> doesn't store the function object away anywhere, so it doesn't matter that
> it receives a reference.
> I would have liked to be able to leverage the function library for this
> purpose.

I see now what you mean. You want the function library to essentially hold a
reference/pointer to the function object you pass in and not ever make a copy
of it.

If this were to be an addition to the function library, would you have a
preferred form? The only form I can think of would be to reuse the "ref"
function used by bind, so one would have:

void foo(boost::function<...> func);

template<typename F>
void bar(F f)
  foo(ref(f)); // boost::function won't allocate any memory or copy f

> > An alternative that would work right now would be to use a custom
> allocator.
> How would that help?

Well, it can solve the stateless function object problem, but not the problem
you're facing.

I'd be willing to support the abovementioned syntax.


Boost list run by bdawes at, gregod at, cpdaniel at, john at