Picon
Favicon

Re: ScopeExit

Steven Watanabe <steven <at> providere-consulting.com> writes:

> 
> AMDG
> 
> The local structs are not essential.  You can
> use tuples.

I like this idea.

> I too would definitely like to see something like
> 
> int main() {
> 
> int i = 0;
> 
> BOOST_LOCAL_FUNCTION(f, (i), (int, v)) {
>     i = v;
> } BOOST_LOCAL_FUNCTION_END;
> 
> f(2); // i = 2
> 
> }

How about this?

int BOOST_LOCAL_FUNCTION( (v) ) (int i)
{
    return v = i;
} BOOST_LOCAL_FUNCTION_END

You can think of it as if BOOST_LOCAL_FUNCTION macro invocation
has been expanded to local function name.
I'm not sure that it's possible in typeof emulation, though :(

Here is how this construction looks after preprocessing:

// Line 1.
int

(*sig_1)();

typedef typeof(v) typeof_v_1;
typedef boost::tuple<typeof_v_1&> tuple_t_1;

tuple_t_1 tuple_1(v);

{ // __LINE__ suffix can be omitted inside this block.

    typedef typeof(sig_1()) result_t;

    typedef tuple_t_1 tuple_t;

    tuple_t& tuple = tuple_1;

    struct scope_exit_body_t {

        typeof_v_1& v;

        scope_exit_body_t(tuple_t& tuple)
          : v(tuple.get<0>())
        {}

        result_t

        // Lines 2-5.
        operator()(int i) const
        {
            return i = v;
        }

        // Line 6.
    };

    typedef typeof(&scope_exit_body_t::operator()) native_typeof_only;
}

> In Christ,
> Steven Watanabe

--
Alexander

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Gmane