digitalmars.D.learn - Foreach type infering only works up to 2 levels?
- Andrej Mitrovic (14/14) Feb 02 2011 int[][][][] multiArray;
- Andrej Mitrovic (2/2) Feb 02 2011 Wow disregard this whole post. I've just realized how stupid that looks.
- Jesse Phillips (2/5) Feb 02 2011 See, you have material for a tutorial. I know you wouldn't run out.
- Andrej Mitrovic (3/8) Feb 02 2011 Actually, yes. TDPL doesn't discuss much about multidimensional data,
- Mafi (13/26) Feb 02 2011 I use the following idiom.
- Andrej Mitrovic (2/8) Feb 02 2011 Cool, that fixes the indentation issue. Nice.
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?
Feb 02 2011
Wow disregard this whole post. I've just realized how stupid that looks. Sorry. :)
Feb 02 2011
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.
Feb 02 2011
On 2/2/11, Jesse Phillips <jessekphillips+D gmail.com> wrote:Andrej Mitrovic Wrote:Actually, yes. TDPL doesn't discuss much about multidimensional data, other than the simple 2-dimensional arrays (IIRC).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.
Feb 02 2011
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
Feb 02 2011
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.
Feb 02 2011