January 26, 2009
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)


January 27, 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.
January 27, 2009
Hello Sergey,

> 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.
> 

try indexing it:

template Tuple(T...)
{
alias T Tuple;
}
void foo()
{
alias Tuple!("a", "b", "c") Tpl;
foreach (i,a; Tpl)
 pragma(msg, Tpl[i]);
}

(BTW that is a known bug)


March 29, 2009
BCS schrieb:
> Hello Sergey,
> 
>> 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.
>>
> 
> try indexing it:
> 
> template Tuple(T...)
> {
> alias T Tuple;
> }
> void foo()
> {
> alias Tuple!("a", "b", "c") Tpl;
> foreach (i,a; Tpl)
>  pragma(msg, Tpl[i]);
> }
> 
> (BTW that is a known bug)
> 

Do you know the bug number?
1 2 3
Next ›   Last »