std.format with named args

Vitaliy Fadeev vital.fadeev at gmail.com
Tue Oct 17 06:46:31 UTC 2023


Hi all!
I want readable mixin.
I want pass variable to string.
I want string with named args.
Like this:

```D
     enum JMP_ADDR_R = "RAX";

     mixin( format!"asm {
         jmp [JMP_ADDR_R];
    }"( JMP_ADDR_R ));    // IT NOT WORK
```

Not this:

```D
     enum JMP_ADDR_R = "RAX";

     mixin( format!"asm {
         jmp [%s];
    }"( JMP_ADDR_R ));    // WORK, BUT NOT-READABLE
```

In large code named identifiers more readable.

In future it will used in jump table, like this:

```D
     mixin( format!"asm {
         lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR 
];
         jmp [JMP_ADDR_R];
     }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R ));
```

Please, help me find a solution...
or exists std.format with named args ?
or another solution with named args ?



More information about the Digitalmars-d-learn mailing list