compile time 'address'

Steven Schveighoffer schveiguy at gmail.com
Fri Nov 30 00:24:50 UTC 2018


On 11/29/18 7:23 PM, aliak wrote:
> 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));
> }

Sweet :) wish I had thought of that earlier...

-Steve


More information about the Digitalmars-d mailing list