Compile-time AAs

Jeremie Pelletier jeremiep at gmail.com
Tue Sep 15 09:57:09 PDT 2009


Don Wrote:

> bearophile wrote:
> > Don has recently said that adding dynamic arrays at compile-time looks easy. I'd also like to have compile-time associative arrays. So you can fill them inside a CT function (the compiler may try to do the same for AAs created inside a static this(){}), and save some run time.
> > Even if such compile-time AAs have to be immutable at run-time they can be useful anyway.
> > A smarter implementation of such CT AAs may even use a perfet hashing, to make them quite fast.
> 
> Indeed. I think perfect hashing is one of the primary appeals of a 
> compile-time AA.
> 
> BTW, you can use AAs inside CTFE already. There's probably missing 
> functionality, though -- create a Bugzilla test case for anything you 
> find. The primary thing which is missing is that you can't use an AA 
> literal to populate a runtime AA (this is a backend issue, not a CTFE 
> limitation). You can get the AA keys and values as arrays, though, so 
> you could populate the AA yourself.

Just out of curiosity, how are compile time AAs implemented? The D runtime already handles the creation and lookups of these arrays, so let's suppose I changed my runtime to have a completely different AA implementation, what would happen when you mix both compile time and runtime AAs?



More information about the Digitalmars-d mailing list