Boost logo

Boost :

Subject: Re: [boost] [scope_exit] Boost.ScopeExit capturing 'this'
From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2009-05-08 10:21:35


<adam.butcher <at> selex-comms.com> writes:
> > It should pan out okay -- it is pretty rude to make 'this(...)' a
> > macro, though since C++ doesn't allow that syntax (that I'm aware
> > of) it should be innocuous and will still generate an appropriate
> > error if the user did, in error, use this(...).

I'm not an expert in a preprocessor but if we assume this(arg) macro is ok,
then do(arg) must be ok as well:

#include <boost/preprocessor/cat.hpp>
#include <boost/scope_exit.hpp>

#define BOOST_AUX_SCOPE_EXIT_later() BOOST_SCOPE_EXIT(BOOST_PP_EMPTY())
#define BOOST_AUX_SCOPE_EXIT_end() BOOST_SCOPE_EXIT_END
#define do(when) BOOST_PP_CAT(BOOST_AUX_SCOPE_EXIT_,when)()

int main()
{
  do(later)
  {
    int i = 0;
  } do(end); // or do(ne) ?
}

Gcc 3.4 compiles this code.
Alex


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