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,309 of 33,346   
   James K. Lowden to daniel.kruegler@googlemail.com   
   Re: transform, make_pair, and rvalues   
   14 Apr 14 22:33:15   
   
   From: jklowden@speakeasy.net   
      
   On Sun, 13 Apr 2014 13:51:55 CST   
   Daniel Krügler  wrote:   
      
   > you could change the instantiation to your needs, e.g. to   
   >   
   > make_pair   
   >   
   > or even more general   
   >   
   > make_pair   
      
   Yes, I could, but neither would compile in C++98.  We're in a   
   transition -- and will be for at least a year -- during which both   
   standards need to be supported.   
      
   Having looked further into this today, AFAICT:   
      
   1.  std::transform requires explicit instantiation of any templated   
       function argument.   
   2.  No explicit instantiation of make_pair is portable across   
       C++98 and C++11.   
      
   At least the second fact was known to the committee and to implementors   
   in 2010.   
      
   My impression is that because make_pair was invented for type   
   deduction, the lack of backward compatibility for explicit   
   instantiation was deemed unimportant.  It's not clear to me if the use   
   of make_pair in std algorithms was considered, or if in fact the   
   compiler is supposed to deduce template parameters in that case.   
      
   If 1 and 2 are true, color me both surprised and disappointed.  At   
   least a backwards-compatible name could exist with the old   
   signature, e.g.   
      
   	template    
   	pair   
   	lvalue_pair( const K& k, const V& v) { return make_pair(k,v); }   
      
   That would have permitted simple search-and-replace instead of   
   preprocessor magic or bespoke templates the world over.   
      
   > Your interprettaion is wrong. The problem is not related to the   
   > const-ness of the iterator (or its lack of), but due to the requested   
   > rvalue-character of the std::make_pair argument types.   
      
   Thank you for your answer, and for that clarification.  I had thought   
   perhaps we would need to add functions that return const_iterator.   
      
   Regards,   
      
   --jkl   
      
      
   --   
         [ 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