[Issue 16608] New: 'static foreach', local function template, 'static if', anySatisfy: Only the first iteration seems to work

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Oct 11 12:10:27 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16608

          Issue ID: 16608
           Summary: 'static foreach', local function template, 'static
                    if', anySatisfy: Only the first iteration seems to
                    work
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: acehreli at yahoo.com

import std.meta;

void main() {
    foreach (s; AliasSeq!("a", "b")) {

        // The problem is that this function is called only for the "a"
iteration
        bool condition(string x)() {
            pragma(msg, "comparing ", x, " and ", s);
            return x == s;
        }

        // This condition is expected to be true for the "b" iteration
        static if (anySatisfy!(condition, AliasSeq!("b"))) {
            pragma(msg, "yes for ", s);
        }
        else {
            pragma(msg, "NO for ", s);
        }
    }
}

However, the condition() is called only for "a" and we get "NO" for the "b"
iteration as well:

comparing b and a
NO for a
NO for b       <-- Why didn't we get "comparing b and b" before this?

Ali

--


More information about the Digitalmars-d-bugs mailing list