From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-09-14 03:54:16
Roland Richter wrote:
> Reece and fellow boosters,
> I have a special interest in Output Formatters working together
> with lexical_cast. The idea is this:
> Since lexical_cast internally uses a stringstream and its
> associated operators >> and <<, and since outfmt defines
> << and >> for STL containers, it should be possible to
> lexical_cast any STL container.
> the reverse "input" operation
> boost::lexical_cast< std::vector<int> >( "[ 7, 9 ]" );
> // throws bad_lexical_cast
> fails. This is because lexical_stream turns off white space skipping,
> and outfmt uses "[ ", ", ", and " ]" (with all those nifty spaces)
> as default formatting.
> The problem is that I can't pass any formatting options to
> lexical_stream at runtime. Hence, I'd like to propose that
> a) either the default formatting of containers is changed to
> "[", ",", and "]",
> b) or a compile-time mechanism (macro? template magic?) should
> be provided to set the formatting.
I've made a noise about this in the past. I strongly believe that current
lexical_cast behaviour does not play nice with existing stream operators
(which are commonly written to assume whitespace is skipped). There's no
good reason for that, and lexical_cast should not use the "noskipws" flag.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk