From: hans.bos@xelion.nl   
      
   "Gennadiy Rozental" schreef in bericht   
   news:60b5098d-d0e4-41cf-95e9-615b51f723fd@googlegroups.com...   
   > Using Scott Meyers terminology, why std::vector&& (or for that matter   
   > any other template) is not considered a universal reference? Thus I am   
   > required to provide 2 overloads to "fake" perfect forwarding. Things   
   > quickly become unmanageable once you move toward functions with multiple   
   > arguments (I do realize the same issue exist for any concrete type, but   
   > I hoped templates would behave better).   
      
   There is a special rule for combining reference types in template   
   parameters.   
   E.g. in template void f(T&&), if f() is called with a int&   
   parameter, the type of T (and of T&&) becomes int&.   
      
   The type of std::vector&& will always be a rvalue reference whatever T   
   is.   
      
   >Any reason why is that? Any workarounds?   
      
   I think you can get a similar effect by passing the arguments by value if   
   they have rvalue constructors.   
   You can forward them with std::move. So you will only need one function.   
      
   Eg in. void g(std::string s, std::vector v)   
    { h(std::move(s), std::move(v)); }   
      
   If you pass rvalue references to g(), they will be forwarded to h() and only   
   move constructors will be called. The move constructors may be optimized   
   away by the compiler.   
      
   Greetings,   
   Hans.   
      
      
   --   
    [ 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)   
|