Boost logo

Boost :

Subject: Re: [boost] Interest in breakable labeled scope emulation?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-01-13 19:29:49

Le 14/01/13 00:51, Klaim - Joël Lamotte a écrit :
> On Sun, Jan 13, 2013 at 8:30 PM, Vicente J. Botet Escriba <
> vicente.botet_at_[hidden]> wrote:
>> Exiting from nested loops is something that could be quite complex using
>> structured programming.
>> Named blocks try to make more structured a goto based solution, by
>> allowing only to restart/leave a block from inside it.
>> for(;;)
>> {
>> while (cnd)
>> {
>> if (cnd2) BOOST_BREAK(L); // go to [1]
>> }
>> }
>> // [1]
>> Of course in order to be really structired the jumping to the underlying
>> label should be forbiden (by the compiler), but I don't think that a
>> preprocessor solution could take care of this. So the following not desired
>> and not structured code could compile even if we would like an compile
>> error.
> Ok but then what's the difference with goto and a label? Doesn't it
> already work like that in C++?
> Sorry if it should be obvious...
Yes. The single difference would be where the label appear on the code
and which instruction do you use to exit from the loop and that the
direct use of label/goto is not telling me "please don't use direct goto
to this label, it is intended to be used only inside this block". Even
if the preprocessor don't help here, an offline tool could use this
information to report a warning.

   while (cnd)

     if (cnd2) goto L; // [2]
L:; // [1]

Anyway, it would be great if the C++ language supports this kind of more structured jumps, but I can leave without.


Boost list run by bdawes at, gregod at, cpdaniel at, john at