Boost logo

Boost :

Subject: Re: [boost] Rave for proposed Boost.Local (functions)
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-02-27 18:22:28

On Fri, Feb 25, 2011 at 2:10 PM, Gregory Crosswhite
<gcross_at_[hidden]> wrote:
> I converted all of my code to use the Sequencing Macro Syntax, and then
> after that I converted it all to the Variadic Macro Syntax.  The process was
> completely painless and took probably about 10-15 minutes total for each
> conversion.  It is always satisfying when one gets to make heavy use of the
> backspace key to eliminate now-unneeded code. :-)
> I think that you've got a good compromise with supporting both legacy C++
> compilers with the sequencing syntax and C99 compilers with the variadic
> syntax;  the variadic syntax is a little nicer, but the sequencing syntax
> feels just fine to use as well.  (I am impressed that you managed to work a
> way so that the same macro can accept both syntaxes!)
> The one part that has become slightly more verbose is where I had multiple
> variables that I was binding, since now I need to retype "const bind" for
> each variable rather than supplying them as a list (unless I am
> misunderstanding something).  I think that is a fair trade-off, though,
> since the nested list inside the const bind used in the old syntax feels a
> bit unnatural unless you are used to preprocessor metaprogramming;  it took
> me a while of peering at the documentation to realize that my mistake was
> that I needed two layers of parentheses instead of one to bind a variable
> (that is "(const bind)((x))" instead of "(const bind)(x)"), and even after I
> got used to the syntax (and understood why you did it that way) my most
> common mistake was to forget and only use a single layer of parentheses
> until the compiler yelled at me. :-)
> I would recommend that when you polish up the documentation that you make
> sure to include an example of the case where multiple variable are bound,
> though, since it is not immediately obvious looking at the examples how to
> extrapolate to that case.  (Incidentally, you should definitely update and
> keep around the Grammar appendix since I found it incredibly helpful in
> figuring out exactly how the syntax worked when I got confused!)
> By-the-way, if you want to see how I have been using your code you can check
> out my repository from

I notice that "non_trivial_columns.cpp" still contains the old syntax
-- probably because you are no longer compiling this file...

Also I noticed that you haven't happened to use `const bind&` and
`[const] bind this`. You have used either `const bind` (constant bind
by value) or `bind&` (non-constant bind by reference). I think your
application just did not need const bind by reference `const bind&`
and to bind the object this `[const] bind this`. However, I wanted to
ask you to make sure that my library docs clearly indicates that these
other types of bindings are possible.

A key difference when you bind by constant reference instead that by
(constant) value, is that binding by value (constant or not) makes a
copy of the bound variable value when the local function is
*declared*. Instead biding by constant reference will use the
(constant) value that the bound variable has when the local function
is *called*. For example:

void f() {
    int x = 10;
    void BOOST_LOCAL_FUNCTION(const bind x) { // make a copy of `x` here
        std::cout << x << std::endl;
    } BOOST_LOCAL_NAME(print)
    x = 11;
    print(); // prints 10 (not 11)


void f() {
    int x = 10;
    void BOOST_LOCAL_FUNCTION(const bind& x) { // doesn't copy `x`
        std::cout << x << std::endl;
    } BOOST_LOCAL_NAME(print)
    x = 11;
    print(); // prints 11 (not 10)

In your experience with my library, is this semantic clearly explained
in the docs?

Overall, it looks like your code make a pretty extensive use of my
library. I'm glad you found it useful!



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