Boost logo

Boost :

Subject: Re: [boost] Review Request: Introduction of boost::stringnamespace Re: Review Request: Introduction of boost::stringnamespace
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-02-12 10:16:22


----- Original Message -----
From: "Phil Endecott" <spam_from_boost_dev_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, February 12, 2009 3:12 PM
Subject: Re: [boost] Review Request: Introduction of boost::stringnamespace Re: Review Request: Introduction of boost::stringnamespace

>
> Stewart, Robert wrote:
>> From: Phil Endecott
>>>
>>> What do people think about the string/number conversions in N2408 ?
>>> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2408.html -
>>> what is the status of that?) Unless there's something wrong
>>> with that, I think we should build on it rather than re-inventing
>>> the wheel.
>>
>> Those are C-style. The advantage of a template is that the compiler deduces
>> the correct implementation.
>
> The compiler can also deduce the correct implementation using
> overloading, which is what N2408 proposes for its to_string functions:
>
> string to_string(long long val);
> string to_string(unsigned long long val);
> string to_string(long double val);
>
> For the from_string functionality we hit the standard problem that we
> can't type match on the type of the thing that the result is being
> assigned to:
>
> short a = from_string(s);
> float f = from_string(s);
>
> The compiler can't deduce the correct implementation; we have to tell
> it (unless we pass the result by reference I suppose). We have a
> choice of template syntax:
>
> short a = from_string<short>(s);
> float f = from_string<float>(s);
>
> or the "C like" syntax proposed by N2408 (which I've just noticed
> doesn't mention short anywhere, breaking my example):
>
> int i = stoi(s);
> float f = stof(s);
>
> In terms of syntax the latter is clearly more concise; some might argue
> that it's too concise (i.e. cryptic), but I would say that these
> conversions and their C equivalents are sufficiently commonly used that
> users will quickly learn what they do. But apart from these syntax
> differences, are there any benefits to one version rather than the other?

Generics :)
Vicente


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