| Thread overview | |||||
|---|---|---|---|---|---|
  | 
July 21, 2005 Howto call foreach for void[char[]] | ||||
|---|---|---|---|---|
  | ||||
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
 | ||||
July 21, 2005 Re: Howto call foreach for void[char[]] | ||||
|---|---|---|---|---|
  | ||||
Posted in reply to Dawid Ciężarkiewicz  | 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.
 | |||
July 22, 2005 Re: Howto call foreach for void[char[]] | ||||
|---|---|---|---|---|
  | ||||
Posted in reply to Burton Radons  | 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
 | |||
Copyright © 1999-2021 by the D Language Foundation
 
Permalink
Reply