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 14:11:45

Le 13/01/13 13:30, TONGARI a écrit :
> Hi all,
> One of the few things I appreciate in Java is the labeled-break feature.
> I think C++ would provide it as well in future standard but it seems that
> there's no even such a proposal.
> In lack of the language feature, a simple emulation can be used:
> ---------------------------------------------------
> #define BOOST_SCOPE(name) \
> if (const bool LABELED_SCOPE_##name = false){break(name); name:;} else
> #define break(name) \
> (void)LABELED_SCOPE_##name; goto name;
> ---------------------------------------------------
> Now we can write:
> {
> break(a);
> cout << "123\n";
> }
> The real world usage would reside in nested loop&switch where labeled-break
> really shines.
> Thoughts? Sorry if this idea is too simple and somewhat rejected before...
Beta language provides restart and leave a named blocks which are a
little bit more structured than gotos.

L:: {

  restart L;

  leave L;


which in C/C++ could be implemented as

   //restart L;
   goto restart_L;

   //leave L;
goto leave_L;


Maybe adapting your macros both can be provided

#define BOOST_RESTART(name) \

#define BOOST_LEAVE(name) \

#define BOOST_NAMED_BLOCK(name) \
   if (const bool BOOST_NAMED_BLOCK_##name = false){
(void)BOOST_NAMED_BLOCK_##name; BOOST_NAMED_BLOCK_LEAVE_##name:;} else

With these macros we can be able to do the following





The problem is that BOOST_NAMED_BLOCK(L) is not an statement but two.
Maybe you see a way to workaround this limitation.

I don't know however if the name LEAVE is a better name on the c++ context.


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