|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-09-12 13:20:45
"Reece Dunn" <msclrhd_at_[hidden]> writes:
>>I'm generally not a great fan of statefulness, but this also seems
>>like a reasonable thing to want:
>>
>> namespace io = boost::io;
>> std::cout << io::sequence_delimiters("{ ", " }");
>> std::cout << io::sequence( vec );
>> // output: { 1, 2, 3 }
>
> You can achieve something like this using:
>
> io::formatter< const char * > fmt( "{ ", " }" );
> std::cout << io::sequence( vec ).format( fmt );
>
> If there are any better alternatives, I am willing to listen.
Well, I think my alternative is better if you want a stateful change,
since yours doesn't accomplish that. My suggestion is certainly
consistent with normal io manipulators. The point is to stream a
bunch of sequences without having to repeat the format part.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk