compile time 'address'

aliak something at something.com
Fri Nov 30 00:23:08 UTC 2018


On Thursday, 29 November 2018 at 15:56:54 UTC, Dominic Jones 
wrote:
> Hello,
>
> I would like to capture the "address" of variables at compile 
> time. Something not far from this can be done in C++, namely 
> addresses can be compared but not captured (then compared, or 
> whatever).
>
> [...]

I think you can do that by using aliases. This seems to work:

auto cmp(alias t, alias u)() {
   return &t == &u;
}

void main() {
   auto c0 = 1;
   auto c1 = 2;
   static assert(cmp!(c0, c0));
   static assert(!cmp!(c0, c1));
}

Cheers,
- Ali


More information about the Digitalmars-d mailing list