View Single Post
Old 02-01-2005, 06:32 AM   #8 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
And you'd like to see perhaps some output optimization for HUGE matrices. This technique comes in handy for N x N matrices where hundreds of thousands, millions and more elements could be created:
Code:
template <typename T>
class print_vector
{
public:
   void operator()(const std::vector<T>& v)
   {
      std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
      std::cout<< " " << std::endl;
   }
};

//-------------------------------

template <typename T>
ostream& operator<< (std::ostream&  os, C2DMatrix<T>& c2d)
{
  typename std::vector<std::vector<T> >::iterator it_end = c2d.get_internal_rep().end();  
  typename std::vector<std::vector<T> >::iterator it_begin = c2d.get_internal_rep().begin();
  
  std::for_each( it_begin, it_end, print_vector<T>() );
  
  return os; 
}
Don't forget to make an accessor:
Code:
template <typename T>
C2DMatrix<T>::vector<vector<T> >& get_internal_rep()
{
   return data_;
}
__________________
Valmont is offline   Reply With Quote