|
Boost : |
Subject: Re: [boost] Boost.Conversion - pre review request
From: Jeroen Habraken (vexocide_at_[hidden])
Date: 2011-07-09 11:15:02
Hi,
On 9 July 2011 17:08, Vicente Botet <vicente.botet_at_[hidden]> wrote:
>
> Gordon Woodhull wrote:
>>
>> On Jul 9, 2011, at 10:41 AM, "Hartmut Kaiser"
>> <hartmut.kaiser_at_[hidden]> wrote:
>>
>>>> I don't see why we need to specify that the format is hexadecimal. I
>>>> would
>>>> expect that the spirit grammar associated to the coerce library will
>>>> take
>>>> care of all the formats without any specific additional tag.
>>>
>>> Doing implicit conversion from 0x17 to 'int' without explicit guidance
>>> from the user (i.e. by telling to convert from hex) is not a good idea,
>>> IMHO. I'd suggest to make the conversion explicit as much as possible,
>>> which usually amounts to the least surprised user.
>>
>> E.g. 700 is different values in octal, decimal, hexadecimal.
>>
>>
>
> On the current implementation if you try to convert "700" to an int you will
> get 700. If you want to take it as the representation of other than a
> decimal number you will need to use explicitly a specific library that
> provide it, as Boost.Coerce could do.
>
> If the Boost community consider that there is no good default behavior fro
> string to int conversion I will remove this specializations.
>
> Anyway, what is the result of
>
> Â coerce::as(*int*)("700");
>
> ?
> Best,
> Vicente
The result is 700, however when one takes "3.14" as input things start
to become less obvious. boost.coerce will always parse "3.14" to 3.14
and will always fail on "3,14", boost.lexical_cast however will parse
one and fail on the other depending on the locale.
Jeroen
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk