Boost logo

Boost :

Subject: Re: [boost] [local] couple questions
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-05-27 10:21:32

On Thu, May 26, 2011 at 6:52 PM, Jeffrey Lee Hellrung, Jr.
<jeffrey.hellrung_at_[hidden]> wrote:
> 1) I notice from
> that (proposed) Boost.Local has a dependency on Boost.ScopeExit.  It seems
> that Boost.Local provides all the functionality of Boost.ScopeExit, and then
> some; at least, that's what seems to be implied by
> It would seem reasonable then, maybe, should Boost.Local be accepted, to
> remove the dependence on Boost.ScopeExit and officially deprecate
> Boost.ScopeExit in favor of Boost.Local's BOOST_LOCAL_EXIT:
> What are your (you = Lorenzo or anyone else) thoughts regarding that
> development path?

Yes, it'd make sense to merge Boost.Local and Boost.ScopeExit -- see
footnote 17 at

I'd think then Alexander Nasonov will participate to Boost.Local
review and appear as a Boost.Local co-author.

> 2) I haven't read through the docs in *too* much detail yet, but I would
> guess from, for example,
> that copying a Boost.Local functor amounts to something less than a deep
> copy, and possibly an entirely shallow copy.  In other words, does

The copy is shallow. It essentially copies a couple of function
pointers within boost::local::aux::function and the bound variables
are all internally hold by reference:

However the following example...

> int x = 0;
> void BOOST_LOCAL_FUNCTION_PARAMS( bind(int) x ) { // bind x by value, so a
> copy is taken...
>    std::cout << ++x << std::endl;
> boost::function< void ( ) > g(f);
> f();
> g();
> print "1" followed by "2" (my guess), or does it print "1" twice?  I may

... prints "1" followed by "1" because "x" is bind by value so "x"
becomes 2 only within an execution of the local function and not
across executions (i.e., x is not threated as a static local variable
within the local function). This prints "1" followed by "1" even is
you call f(); f(); instead of f(); g(); so it's not because of copying
f in g but it's because of the binding by value semantics (which are
the same semantics as of Boost.ScopeExit -- but scope exits are always
executed just one time).

This should be explained here:
And if it's not clear I can explain it better...

> have missed it entirely, but I'd like the semantics of copying a Boost.Local
> functor explicitly spelled out.

Yes, I think I should explain this better maybe in:

> P.S.:  I noticed in
> a misspelling in the comments of the last example,

OK, I'll fix it.


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