digitalmars.D - Static Initialization of AAs - when?
- arandomonlooker (8/8) May 28 2022 Hello.
- Steven Schveighoffer (19/27) May 29 2022 You can do this with my [newaa
- arandomonlooker (3/25) May 29 2022 Thank you. This is going to be useful to me anyways.
- Sergey (5/11) May 30 2022 Hi Steven!
- Steven Schveighoffer (12/22) May 30 2022 No, but if anything, I'd expect it to be a tad bit faster, since it
Hello. I am posting here for the first time as a beginner to the D programming language. I was curious about the fact that static initialization of associative arrays, while being present in the specification, it has not yet been implemented in the language. There is a plan to implement it in the future? Thank you all in advance.
May 28 2022
On 5/28/22 8:36 PM, arandomonlooker wrote:Hello. I am posting here for the first time as a beginner to the D programming language. I was curious about the fact that static initialization of associative arrays, while being present in the specification, it has not yet been implemented in the language. There is a plan to implement it in the future? Thank you all in advance.You can do this with my [newaa project](https://code.dlang.org/packages/newaa): ```d import schlib.newaa; auto myAA = Hash!(string, int)(["hello" : 1, "world" : 2]); void main() { int[string] aa = myAA.asAA; writeln(aa); } ``` Not much niceties there yet, notably, it doesn't print out well, or have a good factory function. You also cannot reinterpret as a builtin AA at compile time, because the reinterpret cast isn't possible. But you can just use it as a drop-in replacement for builtin AAs. It actually is binary compatible, so you can have both a normal builtin AA reference to it, and a `Hash` reference, and both will work. -Steve
May 29 2022
On Sunday, 29 May 2022 at 15:34:09 UTC, Steven Schveighoffer wrote:On 5/28/22 8:36 PM, arandomonlooker wrote:Thank you. This is going to be useful to me anyways.[...]You can do this with my [newaa project](https://code.dlang.org/packages/newaa): ```d import schlib.newaa; auto myAA = Hash!(string, int)(["hello" : 1, "world" : 2]); void main() { int[string] aa = myAA.asAA; writeln(aa); } ``` Not much niceties there yet, notably, it doesn't print out well, or have a good factory function. You also cannot reinterpret as a builtin AA at compile time, because the reinterpret cast isn't possible. But you can just use it as a drop-in replacement for builtin AAs. It actually is binary compatible, so you can have both a normal builtin AA reference to it, and a `Hash` reference, and both will work. -Steve
May 29 2022
On Sunday, 29 May 2022 at 15:34:09 UTC, Steven Schveighoffer wrote:On 5/28/22 8:36 PM, arandomonlooker wrote: But you can just use it as a drop-in replacement for builtin AAs. It actually is binary compatible, so you can have both a normal builtin AA reference to it, and a `Hash` reference, and both will work. -SteveHi Steven! What about speed and performance? Did you compare it with built-in AA?
May 30 2022
On 5/30/22 4:39 PM, Sergey wrote:On Sunday, 29 May 2022 at 15:34:09 UTC, Steven Schveighoffer wrote:No, but if anything, I'd expect it to be a tad bit faster, since it doesn't use TypeInfo for many things such as hash calculation, and it can be inlined. It might be slower in CTFE, since the interpreter is running the actual code instead of the builtin CTFE AA. However, you can use the builtin CTFE AA, and then just return a `Hash` as a result. Note that all the factors and the algorithms are identical to how druntime does it (I copied that code verbatim, which is why the copyright is from there). It has to be, because its aim is to be binary compatible. -SteveOn 5/28/22 8:36 PM, arandomonlooker wrote: But you can just use it as a drop-in replacement for builtin AAs. It actually is binary compatible, so you can have both a normal builtin AA reference to it, and a `Hash` reference, and both will work.Hi Steven! What about speed and performance? Did you compare it with built-in AA?
May 30 2022