Boost logo

Boost Users :

From: Victor A. Wagner, Jr. (vawjr_at_[hidden])
Date: 2003-09-03 22:56:31

is this what you had in mind??
I've considered this from time to time (first time I've formalized it tho)
especially thinking of alternatives to the 3 delimiter arguments
(substitute one? "{,}" ??) or what-have-you
maybe we should boostify it?

template <typename InputItr>
ostream& range_streamer(ostream& to, InputItr start, InputItr stop, const
char* sdelim, const char* mdelim, const char* edelim)
         // output the beginning delimiter
         to << sdelim;

         // output the 1st element if it exists
         if (start != stop) to << *start++;

         // output the rest of the list (if any) separated by mdelim
         while (start != stop)
                         to << mdelim << *start;
         //output the ending delimiter and return
         return to << edelim;
and of course, if you're going to do it, do it all the way:
template <typename Container>
inline ostream& container_streamer(ostream& to, Container const& cont,
const char* sdelim, const char* mdelim, const char* edelim)
{return range_streamer(to, cont.begin(), cont.end(), sdelim, mdelim, edelim);}

At Wednesday 2003-09-03 09:07, you wrote:
>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 );
>I'm thinking something like the following usage would be nice:
> s << range_streamer( lInts.begin(), lInts.end(), "{", "," "}" );
>Any thoughts?
>Jeff Flinn
>Applied Dynamics, International

Victor A. Wagner Jr.
The five most dangerous words in the English language:
               "There oughta be a law"

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at