From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-03-16 07:32:00
>From: "Jason House" <jhouse_at_[hidden]>
> Terje Slettebø wrote:
> > std::vector<std::pair<char,int> > test;
> > std::cout << test: // Using defaults
> > (('A',1),('B',2),('C',3))
> I would suspect that chars don't get output with '' around them...
> Is there even a way to specify/change that? Something similar for
> strings (along with an escape character) would be very handy for
I've found a way this may be done. If you specify "start element" and "end
element" strings, in addition, it may be done. Currently, it takes "start
sequence", "end sequence", and "delimiter", so this would mean two
(optional) more. E.g.:
typedef std::vector<char> vector_char;
// Fill with 'A', 'B', 'C'
std::cout << io::format<vector_char>("[", "]", ", ", "\'", "\'") << values;
['A', 'B', 'C']
However, is this overkill?
Even if the last two are optional, it means the output routines have to
output (possibly empty) strings before and after each element, in addition
to the delimiter.
Feedback is most welcome.
> > There was a suggestion for allowing generic formats, though, using
> > the same format for all instantiations of a template. The question is
> > do it. The current version stores the format for each specific type, as
> > say. Volodya suggested a couple of ways it could be done, partial
> > specialisation, or storing the template name in a map.
There's yet another alternative way this may be done, using "placeholder"
std::cout << io::format<std::vector<_> >(...); // Sets the format for all
std::cout << io::format<_>(...); // Sets the format for all types (defaults)
This would avoid hardcoding any defaults, as the user could change it.
The output routines could then check the formats in the following order,
e.g. for "std::vector<char>":
If there's a format set for std::vector<char>, use it, else
if there's a format set for std::vector<_> (all vectors), use it, else
use format for _.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk