Re: rvalue based copy

2015-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/15 1:42 PM, matovitch wrote: On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: Annoying as this is (and blatantly awkward), it saves you from having to implement twice: void opAssign(T)(auto ref const T s) if(is(T == S)) {...} Yep, this seems awkward to me too th

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: Annoying as this is (and blatantly awkward), it saves you from having to implement twice: void opAssign(T)(auto ref const T s) if(is(T == S)) {...} Yep, this seems awkward to me too thought according to Adam one can do :

Re: rvalue based copy

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: One solution is to overload void opAssign(ref const S s) {...} void opAssign(const S s) {...} lvalues will go into the ref version, rvalues into the non-ref. There won't be any copying of data, so you still save a postblit

Re: rvalue based copy

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:20:30 UTC, matovitch wrote: Yes but you know what they say does it really do a copy of the struct or is the compiler smart enougth most of the time to avoid copy. (I think it's called return value optimization). Copying isn't necessarily a problem, for small stru

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:14:27 UTC, Adam D. Ruppe wrote: On Monday, 30 March 2015 at 17:09:14 UTC, matovitch wrote: (I am gessing ref argument explitly means no rvalue) That's right. I'd first say don't use ref, just use "const S" and it will work and probably do what you need efficient

Re: rvalue based copy

2015-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/15 1:09 PM, matovitch wrote: Hi, Surely I am misunderstanding something. I got something like this : struct S { void opAssign(const ref s) { //... } } S genS() { S s; //... return s; } main() { S s; s = genS(); } DMD says : ...opAssig

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
The title should be assignement not copy.

Re: rvalue based copy

2015-03-30 Thread matovitch via Digitalmars-d-learn
void opAssign(const ref s) should be void opAssign(const ref S s) btw and btw bis, I should probably make it const ref SopAssign(const ref S s) :/ I stop flooding there.

Re: rvalue based copy

2015-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:09:14 UTC, matovitch wrote: (I am gessing ref argument explitly means no rvalue) That's right. I'd first say don't use ref, just use "const S" and it will work and probably do what you need efficiently. If you do want it to be ref though, rvalues aren't allowed