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 33,095 of 33,346   
   =?ISO-8859-1?Q?=D6=F6_Tiib?= to Chris Vine   
   Re: template virtual methods   
   27 May 13 14:19:44   
   
   From: ootiib@hot.ee   
      
   On Monday, 27 May 2013 19:19:58 UTC+3, Chris Vine  wrote:   
   > On Sun, 26 May 2013 22:19:18 -0700 (PDT)   
   >   
   > �� Tiib  wrote:   
   > > On Monday, 27 May 2013 04:23:17 UTC+3, Chris Vine  wrote:   
   > >   > On Sun, 26 May 2013 00:05:29 -0700 (PDT)   
   > >   > �� Tiib  wrote:   
   > >   > > My bet goes to complexity and no gain. Can you provide   
   > >   > > example for what to use such a thing? I can't (so "no gain"   
   > >   > > part is just maybe my bad imagination).   
   > >   >   
   > >   > Yes, you can't do perfect forwarding of arguments with virtual   
   > >   > functions, as forwarding requires the argument type to be   
   > >   > templated. You end up passing class types by reference to   
   > >   > const, which eliminates the possibility of moving a temporary.   
   > >   
   > > Aren't rvalue references meant for temporaries? AFAIK those do not   
   > > have to reference templated types and may well be parameters (or   
   > > return values) of virtual member functions. I would use a pair of   
   > > virtual overloads instead of a virtual template in such context   
   > > because those feel less complex.   
   >   
   > Yes you can provide rvalue reference argument overloads for a   
   > virtual function, but the number of permutations of lvalues with   
   > rvalues makes this impractical for any function which takes more   
   > than about two arguments of class type (and even that can be   
   > impractical, or at least grossly verbose, if the function concerned   
   > has other overloads for other purposes).   
      
   Can a virtual that accepts 3+ templatized collapsible references to   
   (possibly) movable types be somehow elegant for anything?  Only meta   
   programming, variadic templates and operator overloading are yet   
   missing from whole wikipedia of most complex C++ features.   
      
   Move is optimization. When it is beneficial then require rvalue for   
   movable parameters of such anyway complex virtual. It at least removes   
   need for templates/overloads.   
      
   > That is why perfect forwarding using collapsible references of   
   > templated types was implemented.  Template type deduction will   
   > provide you with a rvalue reference or lvalue reference   
   > automatically.   
      
   I had impression that C++ was invented as more convenient, safe and   
   elegant C. However if to pile lot of its complexities into single   
   member function then that likely results with inelegant, frail and   
   cryptic code.  That defeats the purpose, since plain C wins such C++.   
      
      
   --   
         [ 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