Re: Constraints error messages [Was: Re: Constrained Templates]

2010-06-15 Thread bearophile
BCS: I like the idea, but how should it interact with overloaded templates? The syntax/semantics I have shown is just a starting point, there are probably way better ways to reach the same goal. For example a kind of run-time error/exception for templates that shows an error message and

Re: Constrained Templates

2010-06-14 Thread Simen kjaeraas
Leandro Lucarella llu...@gmail.com wrote: it would be nice to have some sort of way to tell the compiler to write the template constraints for us (the obvious ones at least, there might be other template constraints desired besides the ones the ones the compiler can figure out). This way, the

Re: Constrained Templates

2010-06-14 Thread Jason House
Simen kjaeraas Wrote: Leandro Lucarella llu...@gmail.com wrote: it would be nice to have some sort of way to tell the compiler to write the template constraints for us (the obvious ones at least, there might be other template constraints desired besides the ones the ones the compiler can

Re: Constrained Templates

2010-06-14 Thread Don
Simen kjaeraas wrote: Leandro Lucarella llu...@gmail.com wrote: it would be nice to have some sort of way to tell the compiler to write the template constraints for us (the obvious ones at least, there might be other template constraints desired besides the ones the ones the compiler can figure

Re: Constrained Templates

2010-06-14 Thread Simen kjaeraas
Don nos...@nospam.com wrote: This can be trivially shown to be NP-complete. void bar(T)() { static if ( big_function!T) { T t; t.flabbergast( ); } } Compiler cannot determine if T needs flabbergast(), unless it evaluates big_function. Which can be arbitrarily

Constraints error messages [Was: Re: Constrained Templates]

2010-06-14 Thread bearophile
Yao G.: Something I would like to see with template constraints, is the ability to show text messages, like when static if is used. This is a problem I too have. In D1 I used to write code like: template Foo(T) { static assert(condition1, error message1); static assert(condition2, error

Re: Constraints error messages [Was: Re: Constrained Templates]

2010-06-14 Thread BCS
Hello bearophile, A syntax like the following allows to add the user-defined error messages too, but it's bad looking, so probably something quite better can be invented: template Foo(T) if (condition1) else pragma(msg, error message1) if (condition2) else pragma(msg, error message2) { } I

Constrained Templates

2010-06-13 Thread Walter Bright
http://www.drdobbs.com/blog/archives/2010/06/constrained_tem.html Anyone want to do the honors and post to reddit, ycombinator, etc. ?

Re: Constrained Templates

2010-06-13 Thread Leandro Lucarella
Walter Bright, el 13 de junio a las 12:01 me escribiste: http://www.drdobbs.com/blog/archives/2010/06/constrained_tem.html Anyone want to do the honors and post to reddit, ycombinator, etc. ? Nice article, but when I read: T gcd(T)(T a, T b) if (is(typeof(a % b)))

Re: Constrained Templates

2010-06-13 Thread Yao G.
Andrei used that idiom quite extensive in Phobos, unfortunately, I dare to say. It makes the code a lot harder to read. But the alternative, using __traits(compiles, ... ) is even worse IMO, because even as is a little more obvious, is quite verbose. Something I would like to see with

Re: Constrained Templates

2010-06-13 Thread Walter Bright
Yao G. wrote: Maybe I did something wrong at the moment I submitted the article. :( I sent an email to the reddit moderators asking what's up with that.

Re: Constrained Templates

2010-06-13 Thread Ali Çehreli
Leandro Lucarella wrote: Walter Bright, el 13 de junio a las 12:01 me escribiste: http://www.drdobbs.com/blog/archives/2010/06/constrained_tem.html Anyone want to do the honors and post to reddit, ycombinator, etc. ? Nice article, but when I read: T gcd(T)(T a, T b) if

Re: Constrained Templates

2010-06-13 Thread Andrei Alexandrescu
Walter Bright wrote: Yao G. wrote: Maybe I did something wrong at the moment I submitted the article. :( I sent an email to the reddit moderators asking what's up with that. I posted this as a test: http://www.reddit.com/r/reddit.com/comments/cemtc/tech_talk_tips/ Andrei

Re: Constrained Templates

2010-06-13 Thread Yao G.
It is now displayed in the front page. http://www.reddit.com/r/programming/ On Sun, 13 Jun 2010 15:42:13 -0500, Walter Bright newshou...@digitalmars.com wrote: Yao G. wrote: Maybe I did something wrong at the moment I submitted the article. :( I sent an email to the reddit moderators

Re: Constrained Templates

2010-06-13 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message news:hv39tt$87...@digitalmars.com... http://www.drdobbs.com/blog/archives/2010/06/constrained_tem.html Anyone want to do the honors and post to reddit, ycombinator, etc. ? and a line number pointing into the template body. The error is

Re: Constrained Templates

2010-06-13 Thread Steven E. Harris
Leandro Lucarella llu...@gmail.com writes: When you get used to this idiom, it might not look to bad, but I'm seeing people new to D wonder why in the hell was that syntax used? while they try to decode what is(typeof()) means. The syntax doesn't bother me as much as the suggestion to repeat

Re: Constrained Templates

2010-06-13 Thread BCS
Hello Ali, The method that I learned from Phobos is not the best, but at least the function interface reads better: T gcd(T)(T a, T b) if (supports_modulus!T) { T result; // ... return result; } That makes it clear that T must support the modulus operation. Here is how supports_modulus may

Re: Constrained Templates

2010-06-13 Thread BCS
Hello Nick, Walter Bright newshou...@digitalmars.com wrote in message news:hv39tt$87...@digitalmars.com... http://www.drdobbs.com/blog/archives/2010/06/constrained_tem.html Anyone want to do the honors and post to reddit, ycombinator, etc. ? and a line number pointing into the template

Re: Constrained Templates

2010-06-13 Thread Walter Bright
Yao G. wrote: It is now displayed in the front page. http://www.reddit.com/r/programming/ On Sun, 13 Jun 2010 15:42:13 -0500, Walter Bright newshou...@digitalmars.com wrote: Yao G. wrote: Maybe I did something wrong at the moment I submitted the article. :( I sent an email to the

Re: Constrained Templates

2010-06-13 Thread Walter Bright
Nick Sabalausky wrote: and a line number pointing into the template body. The error is being reported as occurring somewhere other than where the actual problem is That would be a good place to point out that recent versions of DMD display template instantiation traces upon template

Re: Constrained Templates

2010-06-13 Thread Andrei Alexandrescu
Walter Bright wrote: Nick Sabalausky wrote: and a line number pointing into the template body. The error is being reported as occurring somewhere other than where the actual problem is That would be a good place to point out that recent versions of DMD display template instantiation traces

Re: Constrained Templates

2010-06-13 Thread Nick Sabalausky
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message news:hv46bv$1kp...@digitalmars.com... Walter Bright wrote: Nick Sabalausky wrote: and a line number pointing into the template body. The error is being reported as occurring somewhere other than where the actual problem is

Re: Constrained Templates

2010-06-13 Thread Andrei Alexandrescu
Walter Bright wrote: Yao G. wrote: It is now displayed in the front page. http://www.reddit.com/r/programming/ On Sun, 13 Jun 2010 15:42:13 -0500, Walter Bright newshou...@digitalmars.com wrote: Yao G. wrote: Maybe I did something wrong at the moment I submitted the article. :( I sent