digitalmars.D.learn - Why does this work?
- h_zet (12/12) Jun 23 2014 import std.typecons;
- VonGrass (3/15) Jun 23 2014 Looks grammaticallyu correct: R type is guessed/infered from the
- hane (14/26) Jun 23 2014 You declared a variable template named "tuple" (with unused type
- h_zet (2/33) Jun 23 2014 Problem solved, Thank you so much!
- bearophile (5/6) Jun 24 2014 I don't think it's solved. There are probably bugs worth
- bearophile (3/5) Jun 24 2014 I have not found them, sorry for the noise.
- Meta (3/8) Jun 24 2014 This looks really bad. I thought we weren't going to allow
- Mason McGill (13/25) Jun 23 2014 Strange behavior, indeed. It took me a minute, but I think I know
- Mason McGill (3/15) Jun 23 2014 It looks like I'm mistaken. Variable templates are supposed to
- bearophile (6/7) Jun 23 2014 When you play a little with this code it's easy to see _error_
import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?
Jun 23 2014
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote:import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?Looks grammaticallyu correct: R type is guessed/infered from the parameter
Jun 23 2014
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote:import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?You declared a variable template named "tuple" (with unused type parameters a, b) on that line. http://dlang.org/template.html#variable-template I think this is very confusable syntax... void main() { auto tuple(a, b) = foo2(1); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1, true)" tuple!(int, int) = foo2(20); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20, true)" }
Jun 23 2014
On Monday, 23 June 2014 at 09:09:56 UTC, hane wrote:On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote:Problem solved, Thank you so much!import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?You declared a variable template named "tuple" (with unused type parameters a, b) on that line. http://dlang.org/template.html#variable-template I think this is very confusable syntax... void main() { auto tuple(a, b) = foo2(1); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1, true)" tuple!(int, int) = foo2(20); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20, true)" }
Jun 23 2014
h_zet:Problem solved, Thank you so much!I don't think it's solved. There are probably bugs worth reporting here. Bye, bearophile
Jun 24 2014
I don't think it's solved. There are probably bugs worth reporting here.I have not found them, sorry for the noise. Bye, bearophile
Jun 24 2014
On Tuesday, 24 June 2014 at 10:11:05 UTC, bearophile wrote:This looks really bad. I thought we weren't going to allow variable templates, just enums and aliases?I don't think it's solved. There are probably bugs worth reporting here.I have not found them, sorry for the noise. Bye, bearophile
Jun 24 2014
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote:import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?Strange behavior, indeed. It took me a minute, but I think I know what's going on, and I'm pretty sure it's a bug. D recently introduced a short syntax for function-like templates: enum a(b) = "some_value"; It looks like this also (sort of) works with other qualifiers, which I believe it shouldn't. Here's a minimal example that might be good to put in a bug report: void main() { enum a(x) = "some_value"; // Good. auto b(x) = "some_value"; // Huh? // This also works for `const`, `static`, etc. }
Jun 23 2014
On Monday, 23 June 2014 at 09:29:15 UTC, Mason McGill wrote:Strange behavior, indeed. It took me a minute, but I think I know what's going on, and I'm pretty sure it's a bug. D recently introduced a short syntax for function-like templates: enum a(b) = "some_value"; It looks like this also (sort of) works with other qualifiers, which I believe it shouldn't. Here's a minimal example that might be good to put in a bug report: void main() { enum a(x) = "some_value"; // Good. auto b(x) = "some_value"; // Huh? // This also works for `const`, `static`, etc. }It looks like I'm mistaken. Variable templates are supposed to exist. Please ignore the previous post.
Jun 23 2014
h_zet:Why does this work? Or it is a bug?When you play a little with this code it's easy to see _error_ that should not appear. So there's surely something worth reporting as bug, but I don't yet know what. Bye, bearophile
Jun 23 2014