Generating unique identifiers at compile time

JG someone at somewhere.com
Thu Jun 9 21:20:27 UTC 2022


Hi,

As an experiment I have implemented the following kind of pattern 
matching
(by parsing the part of the string before '=').

```d
struct S {
int x;
int y;
}

struct T {
     int w;
     S s;
}
void main()
{
     mixin(matchAssign(q{auto T(first,S(second,third)) = 
T(1,S(2,3));}));
     first.writeln;  // 1
     second.writeln; // 2
     third.writeln;  // 3
}
```
In doing so I wanted to produce unique identifiers (something 
like gensym in racket.) I did this in a very hacky way:

```d
auto hopefullyUniqueName(size_t n, size_t line=__LINE__) {
     return 
format!"____________________________var___________________________%s%s"(n,line);
}
```

where I pass in the hash of the right hand side in the assignment 
in place of n.

Is there some way to ask the compiler for a unique name or a 
better way of achieving this?






More information about the Digitalmars-d-learn mailing list