loop through specific class members
    Sergey Gromov 
    snake.scaly at gmail.com
       
    Mon Jan 26 18:26:28 PST 2009
    
    
  
Mon, 26 Jan 2009 04:50:10 +0000 (UTC), BCS wrote:
> Hello Sergey,
> 
>> foreach() is a runtime construct.  It may be *interpreted* at
>> compile-time, but it's interpreted as if it were run time
>> nevertheless. It dynamically changes the value of 'member' variable.
> 
> OTOH a foreach on a tuple is a compile time construct, but it is a distinct 
> construct from the array foreach and is not what you are using (If i'm reading 
> stuff correctly)
I somehow missed that in the specs.  Definitely, this works:
template Tuple(T...)
{
  alias T Tuple;
}
void foo()
{
  foreach (a; Tuple!(int, char, long))
    pragma(msg, a.stringof);
}
but this doesn't:
template Tuple(T...)
{
  alias T Tuple;
}
void foo()
{
  foreach (a; Tuple!("a", "b", "c"))
    pragma(msg, a);
}
$ dmd -c test.d
test.d(8): Error: string expected for message, not 'a'
test.d(8): Error: string expected for message, not 'a'
test.d(8): Error: string expected for message, not 'a'
*This* seems like a bug to me.
    
    
More information about the Digitalmars-d-learn
mailing list