Is old style compile-time foreach redundant?
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jan 9 15:57:03 UTC 2018
On 1/8/18 9:27 AM, H. S. Teoh wrote:
> On Sun, Jan 07, 2018 at 10:39:19PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:
>> On 1/6/18 6:25 PM, Ali Çehreli wrote:
>>> Is 'static foreach' sufficient for all needs or is there any value
>>> for regular foreach over compile-time sequences?
>>
>> If you use continues or breaks, then you need to switch to gotos if
>> using static foreach, as it does not support them directly.
> [...]
>
> Are you sure? I was under te impression that it does support continues
> and breaks -- but only if they are labelled, because of a syntactic
> ambiguity otherwise.
I thought it only worked for constructs outside the static foreach (like
switch).
testing...
Nope, doesn't work. The ambiguity is that if you have a breakable or
continuable construct outside a static foreach (e.g. switch), then you
may believe that the break statement is affecting the foreach (in fact,
that is how tuple-foreach works), but you are actually affecting the
outer construct. The extra requirement is to help you realize the
implication. It may be removed in the future.
I may have been misleading when I made my first comment. What I mean is
that you *can't* break or continue a static foreach, even with labels.
However, you *can* do it to a standard foreach over a tuple. This may be
one reason you want to use a tuple-foreach over a static foreach.
-Steve
More information about the Digitalmars-d-learn
mailing list