digitalmars.D.learn - inout and foreach elements
- Charlie (9/9) Jun 04 2005 Why does this not work ?
- Vathix (4/12) Jun 04 2005 It won't recalculate the hashes or anything. You would have to remove th...
- Ben Hinkle (5/23) Jun 04 2005 not only that but map.keys returns a dynamic array of the keys. So the
- Derek Parnell (18/32) Jun 04 2005 Try this sort of things instead ...
Why does this not work ? void array_change_key_case( inout char [] [ char [] ] map) { foreach ( inout char [] key;map.keys ) { key = std.string.tolower(key); } } Charlie
Jun 04 2005
On Sat, 04 Jun 2005 17:27:22 -0400, Charlie <charles jwavro.com> wrote:Why does this not work ? void array_change_key_case( inout char [] [ char [] ] map) { foreach ( inout char [] key;map.keys ) { key = std.string.tolower(key); } }It won't recalculate the hashes or anything. You would have to remove the element and add it again with the new key, which can't be done while you're in the foreach loop.
Jun 04 2005
"Vathix" <vathix dprogramming.com> wrote in message news:op.sru8qlhskcck4r esi...On Sat, 04 Jun 2005 17:27:22 -0400, Charlie <charles jwavro.com> wrote:not only that but map.keys returns a dynamic array of the keys. So the foreach code only changes the values inside the dynamic array and doesn't touch the map.Why does this not work ? void array_change_key_case( inout char [] [ char [] ] map) { foreach ( inout char [] key;map.keys ) { key = std.string.tolower(key); } }It won't recalculate the hashes or anything. You would have to remove the element and add it again with the new key, which can't be done while you're in the foreach loop.
Jun 04 2005
On Sat, 4 Jun 2005 16:27:22 -0500, Charlie wrote:Why does this not work ? void array_change_key_case( inout char [] [ char [] ] map) { foreach ( inout char [] key;map.keys ) { key = std.string.tolower(key); } }Try this sort of things instead ... void array_change_key_case( inout char [] [ char [] ] map) foreach(char[] key; map.keys) { char[] newkey; newkey = tolower(key); if (newkey != key) { map[newkey] = map[key]; delete map[key]; } } } -- Derek Parnell Melbourne, Australia 5/06/2005 9:44:35 AM
Jun 04 2005