Boost logo

Boost :

Subject: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakable library?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-09-07 18:02:26


Pierre Morcello wrote:

> I propose a set of macros that allow to break anywhere. Example of
use of the main macro :
>
> // do something...
> BOOST_BREAKABLE
> {
> if (test1)
> {
> break;
> }
> if (test2)
>
> {
>
> break;
>
> }
>
>
> std::cout<<"this is never reached if test1==true or test2==true.
"<<std::endl;
> // do something...
> }
> // here the program continues ...

What about using a lambda?
[&]() -> void
{
     if(test1)
         return;

     if(test2)
         return;

     std::cout << "this is never reached if test1==true or test2==true."
               << std::endl;
     // do something...
}();

That kind of thing can also be made with macros instead of lambdas using
a similar technique to that of Boost.ScopeExit.

This also has the potential of being able to return values, which can be
pretty useful to initialize an object for example.


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