[iterator] Proposal for inclusion of a csv_ostream_iterator class.

Hi folks, Attached is the csv_ostream_iterator class, I frequently use. I think it could be incorporated into the boost.iterator library (if there is no such thing somewhere in the standart or in some boost library so far.) What it does is very similar to the std::ostream_iterator, the only difference is that it does not put a delimiter after the last element inserted. Such as when we write an integer container to a stream with a comma delimiter, we get something like this: { 1, 7, 12, 5, 8, } however by using this class the last delimiter is gone { 1, 7, 12, 5, 8 } which is mostly the intended behavior. It can be used for textual data generation (for correct CSVs and good looking XMLs) including code generation. Note: Works with gcc-4.x, may needs to be modified to be portable. Thanks, Emre Turkay

Emre Turkay wrote:
Hi folks,
Attached is the csv_ostream_iterator class, I frequently use. I think it could be incorporated into the boost.iterator library (if there is no such thing somewhere in the standart or in some boost library so far.)
What it does is very similar to the std::ostream_iterator, the only difference is that it does not put a delimiter after the last element inserted. Such as when we write an integer container to a stream with a comma delimiter, we get something like this: { 1, 7, 12, 5, 8, } however by using this class the last delimiter is gone { 1, 7, 12, 5, 8 } which is mostly the intended behavior.
It can be used for textual data generation (for correct CSVs and good looking XMLs) including code generation.
Note: Works with gcc-4.x, may needs to be modified to be portable.
IIRC, Jonathan Turkanis, the original author of the boost.iostreams had proposed a more general facility. There was much discussion on this mailing list at the time. I don't remember if it made it to a formal review, but it didn't go anywhere after that. I haven't seen Jonathan on this list in quite a while. Jeff Flinn
participants (2)
-
Emre Turkay
-
Jeff F