Boost logo

Boost :

Subject: Re: [boost] Review Request: Introduction of boost::string namespace Re: Review Request: Introduction of boost::string namespace
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2009-02-12 13:57:02


> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
On
> Behalf Of Phil Endecott
> Sent: 12 February 2009 14:13
> To: boost_at_[hidden]
> Subject: Re: [boost] Review Request: Introduction of boost::string
namespace Re:
> Review Request: Introduction of boost::string namespace
>
> 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?

What about handling user-defined types like big integer and big floating
point like NTL ZZ, quad_float, RR, and GMP equivalents? Hardware is unlikely
to go beyond 128 bit FP or int, if that, so we need to think ahead about
more accurate integer and floating-point types in software.

Only the to_string and from_string apply here?

NTL uses the ugly

  RR v;
  v = to_RR("12345.6789");

but

  v = from_string<RR>("12345.6789");

feels better.

Views?

Paul

---
Paul A. Bristow
Prizet Farmhouse
Kendal, UK   LA8 8AB
+44 1539 561830, mobile +44 7714330204
pbristow_at_[hidden]

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