Re: Template mixin + operator overloading question

2019-10-11 Thread Boyan Lazov via Digitalmars-d-learn
On Friday, 11 October 2019 at 13:13:46 UTC, Dennis wrote: On Friday, 11 October 2019 at 12:45:59 UTC, Boyan Lazov wrote: Any ideas what I'm doing wrong? Nothing, it's a bug. https://issues.dlang.org/show_bug.cgi?id=19476 Alright, I see Well, the alias workaround works, so that seems just as

Re: Template mixin + operator overloading question

2019-10-11 Thread Dennis via Digitalmars-d-learn
On Friday, 11 October 2019 at 12:45:59 UTC, Boyan Lazov wrote: Any ideas what I'm doing wrong? Nothing, it's a bug. https://issues.dlang.org/show_bug.cgi?id=19476

Template mixin + operator overloading question

2019-10-11 Thread Boyan Lazov via Digitalmars-d-learn
Hello, I seem to have a problem when I use a template mixin and then try to overload operators both in the mixin and in a struct from where it's instantiated. So the idea is that I have a few operators defined in the mixin, then a few more in the struct, and I want to forward all operations n

Re: ref + operator overloading question

2013-09-16 Thread Namespace
On Monday, 16 September 2013 at 21:01:48 UTC, Aleksey wrote: On Monday, 16 September 2013 at 20:53:18 UTC, Namespace wrote: On Monday, 16 September 2013 at 20:43:01 UTC, Aleksey wrote: I get strange type errors in the following code, and I don't understand why =( Could anybody help? struct I {

Re: ref + operator overloading question

2013-09-16 Thread Namespace
On Monday, 16 September 2013 at 20:43:01 UTC, Aleksey wrote: I get strange type errors in the following code, and I don't understand why =( Could anybody help? struct I { int i; I opBinary(string op)(ref I that) if (op == "+") { return I(i + that.i); } } void m

ref + operator overloading question

2013-09-16 Thread Aleksey
I get strange type errors in the following code, and I don't understand why =( Could anybody help? struct I { int i; I opBinary(string op)(ref I that) if (op == "+") { return I(i + that.i); } } void main() { auto a = I(1); auto d = a + (a + a); } Er

Re: ref + operator overloading question

2013-09-16 Thread Aleksey
On Monday, 16 September 2013 at 20:53:18 UTC, Namespace wrote: On Monday, 16 September 2013 at 20:43:01 UTC, Aleksey wrote: I get strange type errors in the following code, and I don't understand why =( Could anybody help? struct I { int i; I opBinary(string op)(ref I that) if (o

Re: Operator overloading question

2013-01-22 Thread Timon Gehr
On 01/21/2013 07:53 PM, Ali Çehreli wrote: ... void foo(string s == "hello")() // ERROR; I don't think possible { // ... } void foo(string s : "hello")(){ // ... }

Re: Operator overloading question

2013-01-21 Thread mist
On Monday, 21 January 2013 at 18:53:08 UTC, Ali Çehreli wrote: ... Can you elaborate. I don't see the duplication. Ali First we check that parameter is one of allowed ones in constraint. Then we do the very same check using the very same operator list to actually make a right dispatch. Looks

Re: Operator overloading question

2013-01-21 Thread Ali Çehreli
On 01/21/2013 10:02 AM, mist wrote: > Hm, but why can't static assert provide an instantiation trace? I can > live without error message I forgot to mention that template constraints take part in choosing the implementation as well: void foo(string s)() if ((s == "hello") || (s == "goodbye

Re: Operator overloading question

2013-01-21 Thread mist
Hm, but why can't static assert provide an instantiation trace? I can live without error message but duplicating same condition twice (one time being part of implementation) hurts my eyes :( On Monday, 21 January 2013 at 17:16:22 UTC, Ali Çehreli wrote: On 01/21/2013 08:32 AM, mist wrote: > p

Re: Operator overloading question

2013-01-21 Thread Ali Çehreli
On 01/21/2013 08:32 AM, mist wrote: > phobos style > guidelines favor constraints heavily over static asserts but this > exactly the example when I am uneasy about such choice: static assert > can both provide more user-friendly error message here and remove some > code duplication. Agreed but t

Re: Operator overloading question

2013-01-21 Thread mist
Do you want to discuss it? :) I have noticed that phobos style guidelines favor constraints heavily over static asserts but this exactly the example when I am uneasy about such choice: static assert can both provide more user-friendly error message here and remove some code duplication. On Mo

Re: Operator overloading question

2013-01-21 Thread bearophile
Nathan M. Swan: The correct keyword is "opBinary", not "opbinary". The compiler must give an error message easy to understand in similar wrong cases. http://dpaste.1azy.net/b73ef2cd This is your code: Arithmetic opbinary(string op)(Arithmetic rhs) { stat

Re: Operator overloading question

2013-01-20 Thread Joseph Cassman
On Monday, 21 January 2013 at 06:51:23 UTC, Nathan M. Swan wrote: On Monday, 21 January 2013 at 06:19:47 UTC, Joseph Cassman wrote: Please refer to http://dpaste.dzfl.pl/edit/b73ef2cd The code is contrived but is trying to focus on overloading the "+" and "*" operators for a struct. Here is

Re: Operator overloading question

2013-01-20 Thread Nathan M. Swan
On Monday, 21 January 2013 at 06:19:47 UTC, Joseph Cassman wrote: Please refer to http://dpaste.dzfl.pl/edit/b73ef2cd The code is contrived but is trying to focus on overloading the "+" and "*" operators for a struct. Here is the output. /home/c215/c527.d(36): Error: incompatible types for (

Operator overloading question

2013-01-20 Thread Joseph Cassman
Please refer to http://dpaste.dzfl.pl/edit/b73ef2cd The code is contrived but is trying to focus on overloading the "+" and "*" operators for a struct. Here is the output. /home/c215/c527.d(36): Error: incompatible types for ((x) + (y)): 'Arithmetic!(int)' and 'Arithmetic!(int)' /home/c215/c