Boost logo

Boost :

From: Roland Richter (roland_at_[hidden])
Date: 2004-09-13 17:28:47

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.

  Well, in theory.

  While it works for "output" operations like this

    std::vector<int> v; v.push_back( 7 ); v.push_back( 9 );
    boost::lexical_cast<std::string>( v ); // gives "[ 7, 9 ]"

  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.

  Ok, I just tested this lexical_cast-specific behaviour,
  thus I can't really answer most of the other questions:

> 1. What is your evaluation of the design?
> 2. What is your evaluation of the implementation?
> 3. What is your evaluation of the documentation?
> 4. What is your evaluation of the potential usefulness of the library?

  Quite useful. Indeed, _very, very_ useful if the above-mentioned
  limitations were solved.

> 5. Did you try to use the library?
> With what compiler? Did you have any problems?

  VC++ 7.0; see above.

> 6. How much effort did you put into your evaluation?
> A glance? A quick reading? In-depth study?
> 7. Are you knowledgeable about the problem domain?
> And most important,
> 8. Do you think the library should be accepted as a Boost library?


- Roland

  I noticed that in earlier versions strings within STL containers
  where surrounded by "quotes"; now, they are no longer, which causes
  problems if a string contains ",". Why was that changed?

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