digitalmars.D.bugs - auto in foreach not supported by dmd 0.137
- zwang (9/9) Oct 26 2005 import std.stdio;
- Derek Parnell (10/20) Oct 26 2005 Of course it fails. The 'auto' facility requires a compile-time expressi...
- zwang (2/24) Oct 26 2005 I see no reason why the data type can not be inferred from arrayid.
- Derek Parnell (19/42) Oct 26 2005 I agree. However the 'auto' uses *exactly* the same data type as the
- Ivan Senji (7/58) Oct 27 2005 No sense? But in both these cases the meaning would be the same: infer
import std.stdio; int main(char[][] args){ for(auto i=0; i<args.length; ++i) //this works. writef(args[i]); foreach(auto i; args) //fails to compile writef(i); return 0; }
Oct 26 2005
On Thu, 27 Oct 2005 11:59:11 +0800, zwang wrote:import std.stdio; int main(char[][] args){ for(auto i=0; i<args.length; ++i) //this works. writef(args[i]); foreach(auto i; args) //fails to compile writef(i); return 0; }Of course it fails. The 'auto' facility requires a compile-time expression in order to determine the data type. The syntax for the foreach is 'foreach' '(' [('int' | 'uint') ident,] typeid ident ';' arrayid ')' There is no place for an 'auto' declaration. -- Derek (skype: derek.j.parnell) Melbourne, Australia 27/10/2005 2:56:37 PM
Oct 26 2005
Derek Parnell wrote:On Thu, 27 Oct 2005 11:59:11 +0800, zwang wrote:I see no reason why the data type can not be inferred from arrayid.import std.stdio; int main(char[][] args){ for(auto i=0; i<args.length; ++i) //this works. writef(args[i]); foreach(auto i; args) //fails to compile writef(i); return 0; }Of course it fails. The 'auto' facility requires a compile-time expression in order to determine the data type. The syntax for the foreach is 'foreach' '(' [('int' | 'uint') ident,] typeid ident ';' arrayid ')' There is no place for an 'auto' declaration.
Oct 26 2005
On Thu, 27 Oct 2005 14:37:17 +0800, zwang wrote:Derek Parnell wrote:I agree. However the 'auto' uses *exactly* the same data type as the expression but foreach needs the element's data type and not the array's data type. But as you suggest, I have yet to see a foreach in which the element data type is not redundant. We could have had the syntax as ... 'foreach' '(' [('int' | 'uint') ident,] ident ';' arrayid ')' e.g. foreach(a; args) and that would still make sense to me. But to overload 'auto' with yet another meaning is starting to appear crazy. Oh hang on, there is a special case .... char[] args; foreach( dchar c; args) where the UTF translation is automated for us. -- Derek (skype: derek.j.parnell) Melbourne, Australia 27/10/2005 4:44:11 PMOn Thu, 27 Oct 2005 11:59:11 +0800, zwang wrote:I see no reason why the data type can not be inferred from arrayid.import std.stdio; int main(char[][] args){ for(auto i=0; i<args.length; ++i) //this works. writef(args[i]); foreach(auto i; args) //fails to compile writef(i); return 0; }Of course it fails. The 'auto' facility requires a compile-time expression in order to determine the data type. The syntax for the foreach is 'foreach' '(' [('int' | 'uint') ident,] typeid ident ';' arrayid ')' There is no place for an 'auto' declaration.
Oct 26 2005
Derek Parnell wrote:On Thu, 27 Oct 2005 14:37:17 +0800, zwang wrote:No sense? But in both these cases the meaning would be the same: infer type from available information. IMO this sytax extension would be quite usefull because in foreach you can know the index and array type at compile time (except in your special case) By the way, your definition of foreach syntax is wrong, as the index type doesn't need to be int or uint (for example in associative arrays)Derek Parnell wrote:I agree. However the 'auto' uses *exactly* the same data type as the expression but foreach needs the element's data type and not the array's data type. But as you suggest, I have yet to see a foreach in which the element data type is not redundant. We could have had the syntax as ... 'foreach' '(' [('int' | 'uint') ident,] ident ';' arrayid ')' e.g. foreach(a; args) and that would still make sense to me. But to overload 'auto' with yet another meaning is starting to appear crazy.On Thu, 27 Oct 2005 11:59:11 +0800, zwang wrote:I see no reason why the data type can not be inferred from arrayid.import std.stdio; int main(char[][] args){ for(auto i=0; i<args.length; ++i) //this works. writef(args[i]); foreach(auto i; args) //fails to compile writef(i); return 0; }Of course it fails. The 'auto' facility requires a compile-time expression in order to determine the data type. The syntax for the foreach is 'foreach' '(' [('int' | 'uint') ident,] typeid ident ';' arrayid ')' There is no place for an 'auto' declaration.Oh hang on, there is a special case .... char[] args; foreach( dchar c; args) where the UTF translation is automated for us.
Oct 27 2005