
on 04.05.2010 at 18:54 Jeffrey Lee Hellrung, Jr. wrote :
On 5/4/2010 12:29 AM, DE wrote:
actually i don't see a reason to implement them that way rather they should be implemented either of two ways
type operator@(type, const type&); type operator#(const type&, const type&);
but not simultaneously in the first case move semantics will take place where appropriate
No good :( Assuming only the *possibility* of reusing resources from your arguments, you want the signature operator+(T,T) if you're adding 2 rvalues, but the signature operator+(const T&, const T&) if you're adding 2 lvalues (so you don't make unnecessary copies compared to passing by value). Unfortunately, you can't have both (ambiguous overload resolution) :/ The only way to get something semantically equivalent is to overload by rvalue reference.
If reuse of resources is *unconditional*, then, sure, pass by value (as long as the swapping/moving is cheap). If reuse of resources *never* happens, then, sure, pass by reference-to-const. Otherwise, the optimal approach is to provide all combinations of rvalue reference and lvalue reference-to-const parameters (in c++03).
sure you are absolutely right i meant only the "unconditional" case -- Pavel P.S. if you notice a grammar mistake or weird phrasing in my message please point it out