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)   
|