Boost logo

Boost Users :

From: Jeff Flinn (yg-boost-users_at_[hidden])
Date: 2003-09-03 11:07:47


Before rolling my own, does boost have a facility to stream out an iterator
range without the dangling delimiter at the end? For example

std::ostream& operator<<( std::ostream& s, const MyClass& aC )
{
  const std::string lDelim( "," );

  std::vector<int> lInts;

  lInts.push_back(1);
  lInts.push_back(2);
  lInts.push_back(3);

  std::ostream_iterator<int> lItr( s, lDelim.c_str() );

  std::copy( lInts.begin(), lInts.end(), lItr );
}

yields:

1,2,3,

I'm thinking something like the following usage would be nice:

    s << range_streamer( lInts.begin(), lInts.end(), "{", "," "}" );

yielding:

{1,2,3}

Any thoughts?

-- 
Jeff Flinn
Applied Dynamics, International

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net