www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - aa literals

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
anyone know of a good (or any) syntax for an empty aa

impetus:

auto aa = reduce!(g)(emptyaa, lst);
Mar 13 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Ellery Newcomer:

 anyone know of a good (or any) syntax for an empty aa
Unfortunately "null" suffices where the function that receives knows the type of the AA it will receive. But I don't like this, a more typed style can be less bug prone. So you can give a type to null: cast(int[string])null I have created a bit shorter template: AA!(string, int) But it doesn't gain much. Something similar can be used for dynamic arrays: cast(int[])null With dynamic arrays you can also use (that I don't like) "null" and even the special [] Bye, bearophile
Mar 13 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Sat, Mar 13, 2010 at 20:17, Ellery Newcomer
<ellery-newcomer utulsa.edu>wrote:

 anyone know of a good (or any) syntax for an empty aa

 impetus:

 auto aa = reduce!(g)(emptyaa, lst);
To associate a list of key/value pairs into one AA? I use .init, but AA in general have become buggy for the past few releases. auto aa = reduce!g((V[K]).init, lst); // this used to work, I think But, as I said, it has become quite buggy recently: auto aa = (int[string]).init; // empty AA? aa["abc"] = 3; // error, no operator [] overload for AssociativeArray!(string, int). I mean, come on. Philippe
Mar 13 2010
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Ellery Newcomer:
 anyone know of a good (or any) syntax for an empty aa
 impetus:
 auto aa = reduce!(g)(emptyaa, lst);
Sorry, I have probably not understood your question. Bye, bearophile
Mar 13 2010
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 03/13/2010 07:20 PM, bearophile wrote:
 Ellery Newcomer:
 anyone know of a good (or any) syntax for an empty aa
 impetus:
 auto aa = reduce!(g)(emptyaa, lst);
Sorry, I have probably not understood your question. Bye, bearophile
No, you hit it on the head. Here's the kind of thing I was after: auto g = reduce!("a[b]=1,a")(cast(int[int]) null, [1,2,3,4]); Works fine. The one-liner probably isn't worth it, but I think it's pretty funny. What does this do to Walter's arguments concerning nonnull?
Mar 13 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Ellery Newcomer:
What does this do to Walter's arguments concerning nonnull?<
I don't understand the question, sorry. Bye, bearophile
Mar 14 2010