Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2007-08-22 03:20:03


I vote to accept BOOST_SCOPE_EXIT.

The library complements scope guard in the same way as BOOST_FOREACH
complements std::for_each. Both of them has a place, and it depends on
the users preferences what they will use. I prefer BOOST_SCOPE_EXIT.

I would wish for a syntax more in line with BOOST_FOREACH (omitting
the BOOST_SCOPE_EXIT_END, but the best I've been able to come up with
is:
{BOOST_SCOPE_EXIT( (commit)(m_persons) )
    {
        if(!commit)
            m_persons.pop_back();
    }
};

With the leading open clause, this is not exactly an improvement...

I too miss the BOOST_LOCAL_FUNCTION_DEF macro. This should be a part
of the library before it is included in boost.

One possible implementation is:

int i=5;
int j=4;
int BOOST_LOCAL_FUNCTION_DEF(name,(i)(j))(int x,int y)
{
   i=x;j=y;
   return i+j;
} BOOST_LOCAL_FUNCTION_DEF_END

//...
name(8,6)

which expands to:
    int i=5;
    int j=4;
    int (*function_ref)()=0;
    typedef BOOST_TYPEOF(i) type_0;
    typedef BOOST_TYPEOF(j) type_1;
    typedef BOOST_TYPEOF(function_ref()) return_type_1;
    struct name_impl {
        type_0& i;
        type_1& j;
        name_impl(type_0& i_,type_1& j_) : i(i_),j(j_) {}
        return_type_1 operator()(int x,int y)
        {
            i=x;j=y;
            return i+j;
        }
    } name(i,j);
    //...

    name(5,6);

When it comes to handle references or copies of arguments, I think the
following can be made to work:
int BOOST_LOCAL_FUNCTION_DEF(name,ref(i)const_ref(j)(k))(int x,int y)
If not, the following can be made to work by using BOOST_PP_IS_UNARY.
( (const&)(i) ) ( j ), but this is starting to look like lisp.

Regards,
Peder


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