Hash Compare
BCS
BCS at pathlink.com
Wed Apr 18 09:23:48 PDT 2007
Johnny wrote:
> Hello,
>
> I've got a problem. I need to check if a hash key exists in a for loop like:
>
> int [char[]] a;
> int [char[]] b;
>
> a = { a => 1; b => 5; c=> 8 }
> b = { a => 5; b => 4; d => 3; f => 4 }
>
> foreach (m; a.keys) {
> if ( b[m] ) {
> writefln("%s %s %s", m, a[m], b[m])
> }
> else {
> writefln("%s %s", m, a[m])
> }
> }
>
> ... not "real" D but I hope you understand the code and what it should do.
> Thanks.
>
What is the issue? That's about as good as anything I can think of. You
might try this (but it's not much better)
foreach (k, v1; a) {
if ( auto v2 = k in b ) // is this what your looking for?
writefln("%s %s %s", k, v1, *v2)
else
writefln("%s %s", k, v1)
}
More information about the Digitalmars-d-learn
mailing list