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,010 of 33,346   
   Chris Uzdavinis to Jonathan Thornburg   
   Re: want to pass vector to fn expe   
   30 Apr 13 22:41:01   
   
   From: cuzdav@googlemail.com   
      
   On Thursday, April 18, 2013 9:50:02 PM UTC-5, Jonathan Thornburg wrote:   
   >   
   > // investigate passing vector to a function expecting vector   
      
   If you don't mind making your implementation itself   
   be a template this is pretty easy to accomplish.   
   Here's the idea.  (I extracted the printing   
   of a single interval to a separate function.)   
      
   void print_interval(interval const * pI)   
   {   
       const interval& I = *pI;   
       cout << "interval " << pI << " = "   
            << "[" << I.min() << ", " << I.max() << "]" << "\n";   
   }   
      
   template    
   void print_vector_of_intervals(const std::vector& vci)   
   {   
       for (typename std::vector::template const_iterator it =   
           vci.begin(); it != vci.end(); ++it)   
       {   
           if (*it)   
               print_interval(*it);   
       }   
   }   
      
      
   and of course, with c++0x you can use auto to clean that up.   
      
       for (auto it = vci.cbegin(); it != vci.cend(); ++it)   
          ...   
      
      
   Chris   
      
      
   --   
         [ 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