Boost logo

Boost :

Subject: Re: [boost] Interest in breakable labeled scope emulation?
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2013-01-15 12:44:17


On Sun, Jan 13, 2013 at 4:30 AM, TONGARI <tongari95_at_[hidden]> wrote:

> 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:
>
> BOOST_SCOPE(a)
> {
> 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...
>

It's a nice thought but:
(a) I think the situation where you want to break and/or continue more than
one loop-level out at a time is rare; and
(b) in those rare situations, explicitly using gotos and labels (with a
descriptive name) is reasonably brief and readable;
so I would be hesitant to adopt this.

- Jeff


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