[Boost-bugs] [Boost C++ Libraries] #7532: lexical_cast fails on complex number with spaces

Subject: [Boost-bugs] [Boost C++ Libraries] #7532: lexical_cast fails on complex number with spaces
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-10-18 19:08:48


#7532: lexical_cast fails on complex number with spaces
-----------------------------------------------+----------------------------
 Reporter: J. J. Ramsey <jjramsey@…> | Owner: apolukhin
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
  Version: Boost 1.50.0 | Severity: Problem
 Keywords: |
-----------------------------------------------+----------------------------
 Here's the test code that shows the problem:

 {{{
 #include <boost/lexical_cast.hpp>
 #include <iostream>
 #include <sstream>
 #include <string>

 typedef std::complex<double> Complex;

 int main()
 {
   std::string goodComplex("(1,2)"), badComplex("(1, 2)");

   try {
     Complex foo = boost::lexical_cast<Complex>(goodComplex);
     std::cout << "goodComplex = " << foo << "\n";
   }
   catch (boost::bad_lexical_cast const & e) {
     std::cerr << "goodComplex failed: " << e.what() << "\n";
   }

   try {
     Complex foo = boost::lexical_cast<Complex>(badComplex);
     std::cout << "badComplex = " << foo << "\n";
   }
   catch (boost::bad_lexical_cast const & e) {
     std::cerr << "badComplex failed: "<< e.what() << "\n";
   }

   {
     /* Using a stringstream works, though. */
     Complex foo;
     std::istringstream tmpStream(badComplex);
     tmpStream >> foo;
     std::cout << "badComplex printed with stringstream = " << foo << "\n";
   }

 }
 }}}

 On my machine, with g++ 4.1.2, I get the following result:

 {{{
 goodComplex = (1,2)
 badComplex failed: bad lexical cast: source type value could not be
 interpreted as target
 badComplex printed with stringstream = (1,2)
 }}}

 For some reason, lexical_cast chokes on the space after the comma, but the
 stringstream has no problem.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7532>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC