Non-static foreach on tupleof has no UDAs?

monkyyy crazymonkyyy at gmail.com
Thu Jul 31 14:44:21 UTC 2025


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:
> ```d
> 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

```d
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"


More information about the Digitalmars-d-learn mailing list