Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-06-05 14:48:53


From: Moore, Paul <paul.moore_at_[hidden]>
> From: David Abrahams [mailto:abrahams_at_[hidden]]
> > Is there any use for the version that fails silently? If
> > there is, I propose that we use the syntax
> > stream_cast<target_type>(source_value, std::no_throw)
>
> A silent failure seems useless. I'd like to see some arguments in favour.
> But if it is included, I like the no_throw syntax you suggest.

I feel that exceptions should be avoidable, so if there isn't some
mechanism for a silent failure, then there should be an easy way for
you to test whether an exception would be thrown:

    std:string s;
    ...
    if (is_a<double>(foo))
    {
        double d = stream_cast<double>(foo);
        ...
    }
    else
    {
        // do something else...
    }

An alternative to the no_throw syntax would be to allow an optional
default value that is to be returned instead of the exception being
thrown:

    double d = stream_cast<double>(s, 0.0); // like atof
    int i = stream_cast<int>(s, INT_MIN);

Mark


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