Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] A suggestion
From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2009-02-03 12:23:04

On Tue, Feb 3, 2009 at 12:41 AM, Vladimir Batov <batov_at_[hidden]> wrote:
> not have any disruptive impact. However, the practical usefulness of that
> addition is substantial (well, for my and I suspect others usage pattern).

Just to jump in here, I'm one of those "others". I ended up writing a
function that try'd the lexical_cast, then on exception, returned the
default value that was passed to the function. I used this often in
parsing files. It looked something like:

template <typename T, typename S>
T try_lexical_cast(const S &value, T default_value)
{ /* stuff */ }

It would be really nice if we didn't have to pay for the cost of an
exception every time that happens in cases where we are expecting lots
of failures but also have an appropriate default value on hand.

And, to be clear, I am *for* Vladimir's addition.

--Michael Fawcett

Boost list run by bdawes at, gregod at, cpdaniel at, john at