Boost logo

Boost :

From: Dave Dribin (dave-ml_at_[hidden])
Date: 2005-04-15 15:05:42


Hi all,

I recently discovered lexical_cast, and it's very nice and elegant.
I'd like to put in a feature request, though: the ability to use a
default value rather than throwing an exception on conversion failure.
Basically, it would take a second argument that would be the value
returned if the conversion fails. This could be used directly in the
example, like:

     std::vector<short> args;

     while(*++argv)
     {
         args.push_back(lexical_cast<short>(*argv, 0));
     }

This eliminates the throwing and catching of an exception for cases
where conversion failure is not an exceptional.

I've attached a patch to lexical_cast.hpp found in Boost 1.32.0

-Dave




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk