www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16608] New: 'static foreach', local function template,


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

import std.meta;

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

        // The problem is that this function is called only for the "a"
        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?


Oct 11 2016