Generic output manipulator for lists
I have a manipulator that will display lists in the basic form: [ i1, i2, ... , in ] It has a usage for a container where it prints the entire container in the list notation; it also has the ability to select the range to be displayed: template< typename ForwardIterator > inline formatlist_t< ForwardIterator > formatlist( ForwardIterator first, ForwardIterator last ); template< typename Container > inline formatlist_t< typename Container::iterator > formatlist( Container & c ); Example usage of the manipulator is thus: std::vector< int > v( 10 ); std::generate( v.begin(), v.end(), std::rand ); // basic list formatting std::cout << "list = " << stl::formatlist( v ) << '\n'; // use the form :- ( i1, ..., in ) std::cout << "list = " << stl::formatlist( v ).format( '(', ')' ) << '\n'; // use the form :- [ i1 | ... | in ] std::cout << "list = " << stl::formatlist( v ).format( '|' ).space( true, true ) << '\n'; You can currently configure the opening and closing elements of the list (default to '[' and ']'); the seperator used (defaults to ','); the spacing around the list (default true) and before/after the seperator (defaults to after the seperator only). I would like to submit it into the boost library. Are there any comments/suggestions/questions? I have currently only tested it with MS VC++.NET 7, but have written the code to not use any MS specific features so it should be usable on most of the current compilers. -rhd- mailto:msclrhd@hotmail.com
From: "Reece H Dunn"
I have a manipulator that will display lists in the basic form: [ i1, i2, ... , in ]
It has a usage for a container where it prints the entire container in the list notation; it also has the ability to select the range to be displayed:
template< typename ForwardIterator > inline formatlist_t< ForwardIterator > formatlist( ForwardIterator first, ForwardIterator last );
template< typename Container > inline formatlist_t< typename Container::iterator > formatlist( Container & c );
Example usage of the manipulator is thus:
std::vector< int > v( 10 ); std::generate( v.begin(), v.end(), std::rand );
// basic list formatting std::cout << "list = " << stl::formatlist( v ) << '\n'; // use the form :- ( i1, ..., in ) std::cout << "list = " << stl::formatlist( v ).format( '(', ')' ) << '\n'; // use the form :- [ i1 | ... | in ] std::cout << "list = " << stl::formatlist( v ).format( '|' ).space( true, true ) << '\n';
You can currently configure the opening and closing elements of the list (default to '[' and ']'); the seperator used (defaults to ','); the spacing around the list (default true) and before/after the seperator (defaults to after the seperator only).
I would like to submit it into the boost library. Are there any comments/suggestions/questions?
I've been working on something similar, here (http://groups.yahoo.com/group/boost/files/composite_stream_operators/). Perhaps we could exchange ideas. Also, maybe you could have provided the code? Regards, Terje
participants (2)
-
Reece H Dunn
-
Terje Slettebø