Boost logo

Boost :

From: Ben Young (ben_at_[hidden])
Date: 2002-05-27 03:19:04


Hi,

I just thought I had better alert you to a possible problem with
lexical_cast, although it is not really lexical_casts fault.

The problem is that some versions of the inputters of streams for unsigned
integer types seem to boil down to a call to strtoul, at least with some
versions of the gcc stl. This then causes the odd semantics that
lexical_cast<unsigned short>("-1") throws bad_cast, but
lexical_cast<unsigned long>("-1") doesn't.

I'm not sure of an easy way around this. As a temporary fix I statically
dispatch to a function which does integer conversions in terms of signed
long longs and then checks the bounds. Of course I now cant use unsigned
long longs, but this usage is much less common than simple unsigned longs.

I'm sure someone can think up a much more satisfactory solution than this.

Cheers

Ben

---

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