|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-12-07 17:47:09
----- Original Message -----
From: rogeeff <rogeeff_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, December 07, 2001 7:09 PM
Subject: [boost] lexical_cast to unsigned
> Hi,
>
> Is it possible to make the lexical_cast to throw an exception in this
> case:
>
> #include <boost/lexical_cast.hpp>
> using namespace boost;
>
> int main()
> {
> unsigned int i;
>
> i = lexical_cast<unsigned int>( "-10" );
>
> return i;
> }
>
>
Probably not, but right now I'm finishing the documentation of the improved
numeric_cast<> that I will submit for formal review very very soon. With it,
you will be able to do this:
#include <boost/lexical_cast.hpp>
#include <boost/numeric_cast.hpp> // improved
using namespace boost;
int main()
{
unsigned int i;
try
{
i = numeric_cast<unsigned int>(lexical_cast<int>( "-10" ));
}
catch ( boost.:negative_overflow )
{
}
return i;
}
Among other useful things!
You can see the *previous* version of this at:
http://groups.yahoo.com/group/boost/files/improved_numeric_cast
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk