Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 4 April 2020 at 12:14:23 UTC, Robert M. Münch wrote: On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){ this.a += rhs.a; this.b += rhs.b; return this;

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/20 8:45 AM, Steven Schveighoffer wrote: >> Yes, sure, but in C++ I don't have to explicitly write this down. It >> just works. IMO that makes a lot of sense as long as all types fit. >> This just looks superfluously. >> > > steves@homebuild:~$ cat test.cpp > struct S > { > float a; >

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/20 8:14 AM, Robert M. Münch wrote: On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){ this.a += rhs.a; this.b += rhs.b; return this; } } If the struct is

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/20 8:07 AM, Robert M. Münch wrote: On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: Probably I didn't understand what you mean. Sorry if this is not the case, but this one is easy. ... struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){   

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, April 4, 2020 4:22:29 AM MDT Robert M. Münch via Digitalmars-d- learn wrote: > D doesn't have implicit operators for structs? > > struct S {float a, float b}; > S a = {1, 5}; > S b = {2, 5); > > a += b; > Error: a is not a scalar, it is a S > > So I really have to write an overloaded

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){ this.a += rhs.a; this.b += rhs.b; return this; } } If the struct is from some 3rd party source, how can I add

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-04-04 10:32:32 +, Ferhat Kurtulmuş said: Probably I didn't understand what you mean. Sorry if this is not the case, but this one is easy. ... struct S { float a; float b; S opOpAssign(string op)(ref S rhs) if (op == "+"){ this.a += rhs.a; this.b +=

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 4 April 2020 at 10:22:29 UTC, Robert M. Münch wrote: D doesn't have implicit operators for structs? struct S {float a, float b}; S a = {1, 5}; S b = {2, 5); a += b; Error: a is not a scalar, it is a S So I really have to write an overloaded operator for such cases? Probably I

No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Robert M. Münch via Digitalmars-d-learn
D doesn't have implicit operators for structs? struct S {float a, float b}; S a = {1, 5}; S b = {2, 5); a += b; Error: a is not a scalar, it is a S So I really have to write an overloaded operator for such cases? -- Robert M. Münch http://www.saphirion.com smarter | better | faster