[Issue 1298] New: More on foreach and tuple

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 29 02:06:01 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1298

           Summary: More on foreach and tuple
           Product: D
           Version: 1.017
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: samukha at voliacable.com


These may be duplicates of other reported tuple bugs. Also, it would be awesome
if some info about compile-time expansion of foreach on tuples is added to docs
(in ForeachStatement section?). Thanks!

All statements in foreach block below should compile for both CTFE and RTFE:

import std.stdio;

template Foo(Strings...)
{
    char[] bar()
    {
        char[] ret;

        foreach (s; Strings)
        {
            static assert(is(typeof(s) : char[]));  //RTFE ok. CTFE fails
            pragma(msg, typeof(s).stringof);  //RTFE ok. CTFE fails

            pragma(msg, s); //Error: string expected for message, not 's'

            ret ~= s; //RTFE ok. CTFE fails
        }

        return ret;
    }
}

void main(char[][] args)
{
    alias Foo!("eeny", "meeny", "miny", "mo") foo;

    static s = foo.bar();

    writefln(foo.bar());
}


-- 



More information about the Digitalmars-d-bugs mailing list