www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Howto call foreach for void[char[]]

reply =?utf-8?B?RGF3aWQgQ2nEmcW8YXJraWV3aWN6?= <arael asn.pl> writes:
Howto make this work:

void[char[]] mSupportedMechanisms;

foreach(char[] mech , void b; mSupportedMechanisms){
   /* foo */
}

As you can see, I need a set. I thought "map is a set with pairs, so why  
not to make void[char[]]". But when comes to using foreach I couldn't find  
a way to get things working.
-- 
Dawid Ciężarkiewicz
Jul 21 2005
parent reply Burton Radons <burton-radons smocky.com> writes:
Dawid Ciężarkiewicz wrote:

 Howto make this work:
 
 void[char[]] mSupportedMechanisms;
 
 foreach(char[] mech , void b; mSupportedMechanisms){
   /* foo */
 }
 
 As you can see, I need a set. I thought "map is a set with pairs, so 
 why  not to make void[char[]]". But when comes to using foreach I 
 couldn't find  a way to get things working.
Use .keys: foreach(char[] mech; mSupportedMechanisms.keys){ } This presently involves an allocation, but the compiler should handle it better in the future. If you must avoid that, then you'll need to use non-void as the value.
Jul 21 2005
parent Chris Sauls <ibisbasenji gmail.com> writes:
Burton Radons wrote:
 This presently involves an allocation, but the compiler should handle it 
 better in the future.  If you must avoid that, then you'll need to use 
 non-void as the value.
Or use 'void[]' or 'void*' as the value. -- Chris Sauls
Jul 21 2005