Loading ...
Sorry, an error occurred while loading the content.
 

ostream_iterator and std::copy - better solutions?

Expand Messages
  • Jeff Flinn
    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&
    Message 1 of 1 , Sep 3, 2003
      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
    Your message has been successfully submitted and would be delivered to recipients shortly.