Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2008-03-17 14:13:53


vicente.botet <vicente.botet <at> wanadoo.fr> writes:

> Hello,
>
> Has somebody news of the scope exit review result? The boost schedule page
> states it as Pending, and the review has been finish 6 months ago?
>
> Regards
>
> Scope Exit Alexander Nasonov Jody Hagins
> August 13, 2007 - August 22, 2007- Pending

There was some discussion of a more generic BOOST_LOCAL_FUNCTION. If used with
ScopeGuard, you can emulate ScopeExit functionality, for example:

// making names a bit shorter: LFN stands for BOOST_LOCAL_FUNCTION
int main()
{
  vector<int> v;
  vector<int>::size_type initial_size = v.size();

  // Declare a nullary functor resize_v_fn
  void LFN(
          LFN_BIND( (ref v)(val initial_size) )
      )
  {
    v.resize(initial_size);
  } LFN_DECL( resize_v_fn )

  ScopeGuard resize_v_guard = make_guard(resize_v_fn);

  // ... push_back one or more elements to v
}

or

int main()
{
  vector<int> v;

  // Declare an unary functor resize_v_fn with only v bound,
  // initial_size will be bound later by make_guard:
  void LFN(
          LFN_BIND( (ref v) ),
          vector<int>::size_type initial_size )
      )
  {
    v.resize(initial_size);
  } LFN_DECL( resize_v_fn )

  ScopeGuard resize_v_guard = make_guard(resize_v_fn, v.size());

  // ... push_back one or more elements to v
}

This could be even make shorter with LFN_ON_EXIT, except that expanded name
BOOST_LOCAL_FUNCTION_ON_EXIT is very long:

int main()
{
  vector<int> v;
  vector<int>::size_type initial_size = v.size();

  // Declare a nullary functor and convert it into a guard:
  void LFN(
          LFN_BIND( (ref v)(val initial_size) )
      )
  {
    v.resize(initial_size);
  } LFN_ON_EXIT

  // ... push_back one or more elements to v
}

So, I'm fine if Jody rejects the ScopeExit library but I can't say when I can
submit LFN for review. I have a working version that don't yet support explicit
binding by reference ( (ref v) in the code above) and by value ( (val
initial_size) ) but I don't have time for further development.

--
Alexander

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