input operators shouldn't clear eof

Oncaphillis oncaphillis at snafu.de
Tue Dec 21 11:31:29 CET 2010


Hi,

This may be more a feature request then a bug report, but the input operator
of gmpxx shouldn't clear the eof flag on the istream.

I very often so string=>number conversion via std::stringstream like in the
flollowing code:

<snip>

#ifdef WITH_GMP
#include <gmpxx.h>
typedef mpz_class   Value_t;
#else
typedef int64_t     Value_t;
#endif


Value_t FromString(const std::string & rVal)
{
     std::stringstream ss(rVal);
     Value_t v;

     if( ! (ss >> v) || !ss.eof() )
     {
         std::cerr << " failed to parse '" << rVal << "' as a number " 
<< std::endl;
         ::exit(1);
     }
     return v;
}
</snip>

Checking eof here tells me that the string has been completely parsed. 
It works fine
with standard types but fails on gmpxx. Checked it on 4.3.2 and 5.0.1

I attached a patch against 5.0.1

O.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gmp.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://gmplib.org/list-archives/gmp-bugs/attachments/20101221/15427c41/attachment.bin>


More information about the gmp-bugs mailing list