6c86552c   
   From: daniel.kruegler@googlemail.com   
      
   Am 07.11.2011 20:52, schrieb Arne Mertz:   
   > On Nov 4, 12:50 am, Daniel Krügler   
   > wrote:   
   >> Am 03.11.2011 19:15, schrieb Jerry:   
   >   
   >> template> class = typename std::enable_if::value>::type   
   >>   
   >> std::vector & operator<<(T&& x,   
   >> const std::vector::value_type& y)   
   >> {   
   >> x.push_back(y);   
   >> return x;   
   >>   
   >> }   
   >>   
   >   
   > Hi Daniel, wouldn't your implementation remove the rvalue-ness from   
   > the first argument?   
      
   It would, but I intentionally suggested to do that in this case   
   nonetheless assuming that the OP intended one of the rare use cases,   
   where this makes sense as in:   
      
   template    
   basic_ostream&   
   operator<<(basic_ostream&& os, const T& x);   
      
   You *could* use this in a wrong way, but I would argue that this so rare   
   that the advantages of this idiom win over the possible risk of misusage.   
      
   > You could write something like this:   
   >   
   > int main()   
   > {   
   > std::vector& ivr = std::vector()<< 5;   
   > ivr<< 6<< 7;   
   > }   
   >   
   > This binds a non-const lvalue-ref to an rvalue, followed by happily   
   > crashing the application...   
      
   Certainly, and I should probably have suggested to the OP *not* to add   
   such an overload anyway (It causes problems all the way, because the   
   operator overload cannot be added to namespace std with all the   
   follow-up problems in regard to ADL). But then I looked at the problem   
   as a variant of the IO insertion and suggested a similar solution. So, I   
   should finish with: "No, don't add such overloads to your code unless   
   you are just playing with the language and don't do serious code   
   writing" ;-)   
      
   Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
    [ 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)   
|