|
Boost : |
Subject: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakablelibrary?
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-09-06 15:48:09
Hi,
----- Original Message -----
From: "Pierre Morcello" <pmorcell-cppfrance_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, September 06, 2009 7:58 PM
Subject: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakablelibrary?
Hi, there is no difference.
Indeed, the macro as I use it right now is even less optimised than a GOTO or a do...while(false) : it's currently just a simple 'for' loop in a macro..
The aim is to make code more readable. A goto is a pain to manage when you use a lot this 'breakable' structure. The fact that it is easy to use and readable makes it easier to use a lot. In the end, I happen myself to use it lot more than I thougth I would at first. That is the main reason why I am proposing it here.
>>>Both are probably shorter to write.
Yes, although someone using such library may redefine the macro as he wishes :
e.g. #define Breakable BOOST_BREAKABLE
I am just conforming to BOOST coding style.
Pierre
--- En date de : Dim 6.9.09, Sebastian Redl <sebastian.redl_at_[hidden]> a écrit :
De: Sebastian Redl <sebastian.redl_at_[hidden]>
Objet: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakable library?
À: boost_at_[hidden]
Date: Dimanche 6 Septembre 2009, 9h10
Pierre Morcello wrote:
> Hello,
>
> 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 ...
>
> Is there any interest in such a library?
>
What's the difference between this and a goto? Or a do ... while(false);
loop? Both are probably shorter to write.
Sebastian
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
The isea to rerplace a goto with a loop and a break is interesting, but I agree with Sebastian, why your macro is more readable than
do {
if (test1)
{
break;
}
if (test2)
{
break;
}
std::cout<<"this is never reached if test1==true or test2==true. "<<std::endl;
// do something...
} while(false);
or
for (bool executed=false;!executed;executed=true) {
if (test1)
{
break;
}
if (test2)
{
break;
}
std::cout<<"this is never reached if test1==true or test2==true. "<<std::endl;
// do something...
}
I'll not include a header library just for this.
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk