| Thread overview | ||||||||
|---|---|---|---|---|---|---|---|---|
|
February 02, 2011 Foreach type infering only works up to 2 levels? | ||||
|---|---|---|---|---|
| ||||
int[][][][] multiArray;
void main()
{
foreach (one, two; multiArray) // ok
{
}
foreach (one, two, three; multiArray) // fail
{
}
}
test.d(13): Error: cannot infer type for two
test.d(13): Error: cannot infer type for three
Same thing happens with hashes as well. Is this a limitation in the language or a bug?
| ||||
February 02, 2011 Re: Foreach type infering only works up to 2 levels? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Wow disregard this whole post. I've just realized how stupid that looks. Sorry. :) | |||
February 02, 2011 Re: Foreach type infering only works up to 2 levels? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Andrej Mitrovic Wrote:
> Wow disregard this whole post. I've just realized how stupid that looks.
>
> Sorry. :)
See, you have material for a tutorial. I know you wouldn't run out.
| |||
February 02, 2011 Re: Foreach type infering only works up to 2 levels? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On 2/2/11, Jesse Phillips <jessekphillips+D@gmail.com> wrote:
> Andrej Mitrovic Wrote:
>
>> Wow disregard this whole post. I've just realized how stupid that looks.
>>
>> Sorry. :)
>
> See, you have material for a tutorial. I know you wouldn't run out.
>
Actually, yes. TDPL doesn't discuss much about multidimensional data, other than the simple 2-dimensional arrays (IIRC).
| |||
February 02, 2011 Re: Foreach type infering only works up to 2 levels? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Am 02.02.2011 20:16, schrieb Andrej Mitrovic:
> int[][][][] multiArray;
>
> void main()
> {
> foreach (one, two; multiArray) // ok
> {
> }
>
> foreach (one, two, three; multiArray) // fail
> {
> }
> }
>
> test.d(13): Error: cannot infer type for two
> test.d(13): Error: cannot infer type for three
>
> Same thing happens with hashes as well. Is this a limitation in the language or a bug?
I use the following idiom.
foreach(x, ref column; array)
foreach(y, ref element; column)
//maybe more...
{
//do something
}
It works because of "constructs take one staement & one block is one statement". It is really great because it leads to such flexible soultions.
You might say it's bad practise bad then you have to say the same about 'else if'.
Mafi
| |||
February 02, 2011 Re: Foreach type infering only works up to 2 levels? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Mafi | On 2/2/11, Mafi <mafi@example.org> wrote:
> foreach(x, ref column; array)
> foreach(y, ref element; column)
> //maybe more...
> {
> //do something
> }
Cool, that fixes the indentation issue. Nice.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply