digitalmars.D.learn - compiler assertion
- Zhenya (21/21) Sep 28 2012 Hi!
- Jonathan M Davis (5/11) Sep 28 2012 It's always a bug in the compiler if you see a compiler assertion. What ...
- Zhenya (3/15) Sep 28 2012 Thank you,understood.
- Philippe Sigaud (31/32) Sep 29 2012 This should work, hopefully:
- Zhenya (5/39) Sep 29 2012 I just wanted to do something like template,that takes value
Hi! Is it normally,that this simple code does'nt compile with this assertion: dmd: template.c:5542: Identifier* TemplateInstance::genIdent(Objects*): Assertion `global.errors' failed. import std.stdio; import std.typetuple; template sum(T:TypeTuple!U,U...) { static if(U.length == 0) enum sum = 0; else enum sum = U[0]+sum!(U[1..$]); } void main() { enum s = sum!(1,2,3,4); writeln(s); } ?
Sep 28 2012
On Friday, September 28, 2012 22:19:56 Zhenya wrote:Hi! Is it normally,that this simple code does'nt compile with this assertion: dmd: template.c:5542: Identifier* TemplateInstance::genIdent(Objects*): Assertion `global.errors' failed.It's always a bug in the compiler if you see a compiler assertion. What you're seeing is probably this bug: http://d.puremagic.com/issues/show_bug.cgi?id=8421 - Jonathan M Davis
Sep 28 2012
On Friday, 28 September 2012 at 20:27:07 UTC, Jonathan M Davis wrote:On Friday, September 28, 2012 22:19:56 Zhenya wrote:Thank you,understood.Hi! Is it normally,that this simple code does'nt compile with this assertion: dmd: template.c:5542: Identifier* TemplateInstance::genIdent(Objects*): Assertion `global.errors' failed.It's always a bug in the compiler if you see a compiler assertion. What you're seeing is probably this bug: http://d.puremagic.com/issues/show_bug.cgi?id=8421 - Jonathan M Davis
Sep 28 2012
On Fri, Sep 28, 2012 at 10:32 PM, Zhenya <zheny list.ru> wrote:Thank you,understood.This should work, hopefully: import std.stdio; import std.typetuple; template sum(U...) { static if(U.length == 0) enum sum = 0; else enum sum = U[0]+sum!(U[1..$]); } void main() { enum s = sum!(1,2,3,4); writeln(s); } You can also do it with a standard function, and forcing its execution at compile-time by using 'enum': U[0] sum(U...)(U u) if (U.length > 0) { U[0] result =0; foreach(value;u) result += value; return result; } void main() { enum s = sum(1,2,3,4); writeln(s); } Note that doing that without any check on the U's is a bit dangerous.
Sep 29 2012
On Saturday, 29 September 2012 at 13:03:31 UTC, Philippe Sigaud wrote:On Fri, Sep 28, 2012 at 10:32 PM, Zhenya <zheny list.ru> wrote:I just wanted to do something like template,that takes value parametres and deduce it's types,so I guess that I can use code that you wrote for it with some type checking.Thank you,understood.This should work, hopefully: import std.stdio; import std.typetuple; template sum(U...) { static if(U.length == 0) enum sum = 0; else enum sum = U[0]+sum!(U[1..$]); } void main() { enum s = sum!(1,2,3,4); writeln(s); } You can also do it with a standard function, and forcing its execution at compile-time by using 'enum': U[0] sum(U...)(U u) if (U.length > 0) { U[0] result =0; foreach(value;u) result += value; return result; } void main() { enum s = sum(1,2,3,4); writeln(s); } Note that doing that without any check on the U's is a bit dangerous.
Sep 29 2012