Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-04-07 07:03:56

I have updated the formatlist library to support the following features,
while remaining 100% compatible with the previous versions I have posted:

[1] boost::io::formatter

This class has been added along with the two mechanisms outlined in my last
post. I have also added examples to demonstrate its usage.

[2] functor-based formatting

I have reworked the code to use functors for outputting the individual
values in the list, rather than sending them directly to the output stream.

This was based on the idea by Jason House on the "io for stl containers"
thread: thanks Jason.

This now allows much greater flexibility than the older list manipulator
implementation and io::format. At the moment, the only requirement is that
you have an operator that has the basic form:

   template< typename T, class OutputStream >
   inline OutputStream & operator()
      OutputStream & os,
      const T & const value
   ) const;

By default, the formatlist_t object uses the boost::io::basic_output
functor, that is equivalent to
   os << value;

This would also allow you to change the way fundamental types are outputted.

[3] std::pair formatting

Using the new functor-based formatting, it is now possible to output
std::pair objects in a custom way that is consistent with the formatlist

See the test.cpp file for examples on how to do this.

NOTE: I am considering extending this for other two-valued types like
complex numbers, as well as providing a formatlist-like manipulator for pair

[4] 2D and nD array formatting

The rendering of nD container types will not, at present, support sub-lists;
it will only work over the entire list, although I am looking at fixing
e.g. std::list< std::vector< char > > nD;

The rendering of nD C-style arrays does support sub-lists in the form
(offset, length).
e.g. int nD[ 3 ][ 4 ][ 5 ] = { ... };

It is also possible to mix arrays and containers.
e.g. std::list< char [ 6 ] > nD;

See the test.cpp file for examples on how to do this.

[5] mix and match formatting

Because the std::pair, array and container outputters use their own
outputter functors, it is possible to nest them to support complex nested
types, for example:
   std::list< std::map< std::string, int > > nested;


I have not worked on any documentation at present, but this will be my next
focus for the library now that the design is essentially stable.

Comments? Suggestions? Ideas? Bugs?


Worried what your kids see online? Protect them better with MSN 8

Boost list run by bdawes at, gregod at, cpdaniel at, john at