Boost logo

Boost :

From: Cory Nelson (phrosty_at_[hidden])
Date: 2006-04-10 21:29:48


On 4/10/06, Phil Nash <phil.nash.lists_at_[hidden]> wrote:
> Maxim Yegorushkin wrote:
> > On 4/10/06, Bronek Kozicki <brok_at_[hidden]> wrote:
> >> Maxim Yegorushkin <maxim.yegorushkin_at_[hidden]> wrote:
> >>> All developers I know roll out their own versions of lexical_cast.
> >>> Last time I checked the implementation of boost::lexical_cast it had
> >>> efficiency bugs. There at least should be specializations for string
> >>> -> integer/double conversions that use strtoul/d functions directly
> >>> rather than iostreams.
> >> the other problem that I have with lexical_cast is that currently it's
> >> impossible to tell whether particular conversion will fail without
> >> actually catching exception (which implies huge performance penalty).
> >> This is needed in all situations where "invalid" input is not an error
> >> (eg. optional data coming from external source)
> >
> > True. Boost have long ignored these issues, no wonder they accepted it
> > tentatively.
>
> The thing is, lexical_cast in its current implementation, is simple and
> elegant, and perfectly usable for most cases.
> It doesn't preclude optimisations in the *implementation*, and some such
> optimisations have been suggested. It would be nice to see some
> actually implemented in the reference implementation.
> As to the error handling - I haven't personally given it much thought -
> but I'm not sure that can be easily parameterised without disturbing the
> interface.

So have a try_lexical_cast which takes a reference to the output var
and returns a bool of success, and have lexical_cast wrap it to throw
an exception on failure.

> Best regards,
>
> [)o
> IhIL..
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>

--
Cory Nelson
http://www.int64.org

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