digitalmars.D - Is this is bug or not?
- Victor Nakoryakov (34/34) Mar 11 2006 Hi all,
- Thomas Kuehne (16/46) Mar 15 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Don Clugston (8/30) Mar 17 2006 If that had worked, it would have been a new feature. You're obtaining a...
- Sean Kelly (14/46) Mar 17 2006 For what it's worth, this is legal in C++:
Hi all, Here is a snipet: import std.stdio; struct A(T, T x0) { T x = x0; } int main(char[][] args) { alias A!(int, 8) Ai; // test.d(11) Ai ai; writefln(ai.x); return 0; } DMD output is: test.d(11): template instance A!(int,8) does not match any template declaration However snipet: import std.stdio; struct A(T, int x0) // note int instead of T { T x = x0; } int main(char[][] args) { alias A!(int, 8) Ai; Ai ai; writefln(ai.x); return 0; } works as expected. Is former is a templates issue or bug? -- Victor Nakoryakov (aka nail) nail-mail[at]mail.ru Krasnoznamensk, Moscow, Russia
Mar 11 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Victor Nakoryakov schrieb am 2006-03-11:Hi all, Here is a snipet: import std.stdio; struct A(T, T x0) { T x = x0; } int main(char[][] args) { alias A!(int, 8) Ai; // test.d(11) Ai ai; writefln(ai.x); return 0; } DMD output is: test.d(11): template instance A!(int,8) does not match any template declaration However snipet: import std.stdio; struct A(T, int x0) // note int instead of T { T x = x0; } int main(char[][] args) { alias A!(int, 8) Ai; Ai ai; writefln(ai.x); return 0; } works as expected. Is former is a templates issue or bug?Added to DStress as http://dstress.kuehne.cn/run/t/template_31_A.d http://dstress.kuehne.cn/run/t/template_31_B.d http://dstress.kuehne.cn/run/t/template_31_C.d http://dstress.kuehne.cn/run/t/template_31_D.d template_31_C seems funny, but I'm not aware of any statement against it. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEGIva3w+/yD4P9tIRAmqnAKCE2FIpTVzbn1maO+6BE6gPkBwDcgCgxT/3 gZtWcBij/IxJZgY31hPA+M8= =vke5 -----END PGP SIGNATURE-----
Mar 15 2006
Thomas Kuehne wrote:-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Victor Nakoryakov schrieb am 2006-03-11:If that had worked, it would have been a new feature. You're obtaining a type AND a value! Note that value parameters only work for basic types and char[]. It would be very cool, though -- it would enable a lot of code reuse for metaprogramming. For example, pow!(real z, int n) and pow!(creal z, int n) would be able to share a common implementation. The fact that they can't has been bugging me for some time.Hi all, Here is a snipet: import std.stdio; struct A(T, T x0) { T x = x0; } int main(char[][] args) { alias A!(int, 8) Ai; // test.d(11) Ai ai; writefln(ai.x); return 0; }
Mar 17 2006
Don Clugston wrote:Thomas Kuehne wrote:For what it's worth, this is legal in C++: #include <iostream> template<class T, T x> struct S { static const T val = x; }; int main() { int x = S<int,5>::val; std::cout << x << '\n'; } Sean-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Victor Nakoryakov schrieb am 2006-03-11:If that had worked, it would have been a new feature. You're obtaining a type AND a value! Note that value parameters only work for basic types and char[]. It would be very cool, though -- it would enable a lot of code reuse for metaprogramming. For example, pow!(real z, int n) and pow!(creal z, int n) would be able to share a common implementation. The fact that they can't has been bugging me for some time.Hi all, Here is a snipet: import std.stdio; struct A(T, T x0) { T x = x0; } int main(char[][] args) { alias A!(int, 8) Ai; // test.d(11) Ai ai; writefln(ai.x); return 0; }
Mar 17 2006