Non-static foreach on tupleof has no UDAs?
monkyyy
crazymonkyyy at gmail.com
Tue Aug 5 15:09:02 UTC 2025
On Tuesday, 5 August 2025 at 14:19:16 UTC, IchorDev wrote:
> On Thursday, 31 July 2025 at 14:44:21 UTC, monkyyy wrote:
>> 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
>
> Nope. I need to declare enums in the foreach body.
This?
```d
import std;
struct enumdef{
string name;
int value;
}
enum string Name(alias T)=__traits(getAttributes, T)[0].name;
enum int Value(alias T)=__traits(getAttributes, T)[0].value;
struct X{
@enumdef("foo",3) string x;
@enumdef("bar",5) string z;
}
void main(){
static foreach(int I,b; X.init.tupleof){
mixin("enum "~Name!b~"=Value!b;");
}
static assert(foo==3);
static assert(bar==5);
}
```
More information about the Digitalmars-d-learn
mailing list