1 day ago

How come doing a foreach on .tupleof causes __traits(getAttributes to return nothing? Is it because it creates a new 'symbol'? Is this a bug?

struct y{
	int z;
}

struct X{
	@y(z: 10) string x;
}

void main(){
	X a;
	foreach(b; a.tupleof){
		pragma(msg, __traits(getAttributes, b)); //AliasSeq!()
	}
}

Changing it to a static foreach prints AliasSeq!(y(10)) as expected, but now I can't use b in runtime code. Obviously there's a workaround, but it's ugly. I'd much prefer if the above code worked rather than having to do this:

static foreach(i; 0..a.tupleof.length){
	pragma(msg, __traits(getAttributes, a.tupleof[i])); //AliasSeq!(y(10))
}
1 day ago

On Thursday, 31 July 2025 at 11:29:41 UTC, IchorDev wrote:

>

I'd much prefer if the above code worked rather than having to do this:

static foreach(i; 0..a.tupleof.length){
	pragma(msg, __traits(getAttributes, a.tupleof[i])); //AliasSeq!(y(10))
}

That verbosity is unnecessary to swap to the other foreach: static foreach(b; a.tupleof){ prints as well

import std;

@"foo" string foo;
@"bar" int bar;

void main(){
	foreach(b; AliasSeq!(foo,bar)){
		pragma(msg, __traits(getAttributes, b));
		pragma(msg,__traits(identifier, b));
		pragma(msg,b.stringof);
	}
	static foreach(b; AliasSeq!(foo,bar)){
		pragma(msg, __traits(getAttributes, b));
		pragma(msg,__traits(identifier, b));
		pragma(msg,b.stringof);
	}
}

I believe we should start calling this first one "alias foreach"