Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-02-10 23:54:21


On Monday 10 February 2003 03:32 pm, Markus Werle wrote:
> Q: I am pretty unsure about dangling references.
> My function object creator functions return
> boost::functions by value (and collect these form others).
>
> If the root function object creator wraps its stuff
> in a cref: does boost lib take care for the lifetime of the
> object? How does this work?

Passing a copy of ref(x) or cref(x) is just like passing x by reference: there
is no transform of ownership, so the Boost lib will _not_ take care of the
lifetime for you. ref/cref is well-suited for cheaply passing function
objects to standard algorithms, but you probably don't want to stick a
ref/cref'd function object into a boost::function object unless you can be
_sure_ that the function object will live longer that the boost::function
object. In the program you described, you'd probably want to keep your array
of boost::function objects but use the bind/(c)ref syntax for passing
function objects to standard algorithms.

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net