home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,569 of 33,346   
   fmatthew5876 to All   
   rvalue references and parameter passing   
   02 Oct 12 16:23:27   
   
   From: fmatthew5876@googlemail.com   
      
   Suppose I have this:   
      
   class Matrix4 {   
    public:   
     //stuff   
    private:   
     float _m[16];   
   };   
      
   Matrix4 operator+(Matrix4 l, const Matrix4& r) {   
    l += r;   
    return l;   
   }   
      
   Is there any possible scenario where I would want to also create   
   a version of operator+ that uses rvalue references? i.e.   
      
   Matrix4 operator+(Matrix4 l, const Matrix4&& r) {   
    l+=r;   
    return l;   
   }   
      
   I understand rvalue references are desirable in most cases because we   
   want to use move constructors instead of making unnecessary copies.   
   But in this particular case, the matrix class directly contains its   
   data instead of doing an allocation so there is no move constructor.   
      
   To put it more succinctly, is there ever a case when the first operator+   
   will create a copy for the second argument where the second operator+   
   would not?   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca