Boost logo

Boost :

Subject: Re: [boost] Checking interest in to_string functions
From: Joshua Juran (jjuran_at_[hidden])
Date: 2011-09-30 13:55:46


On Sep 30, 2011, at 10:13 AM, Olaf van der Spek wrote:

> On Fri, Sep 30, 2011 at 6:54 PM, Stewart, Robert
> <Robert.Stewart_at_[hidden]> wrote:
>> I think it is reasonable to capture to_string() as a standard,
>> extrinsic function template that returns a std::string from T.
>> Each T must supply a specialization that does the right thing, of
>> course,
>
> I was expecting it to be a wrapper around lexical_cast.
>
>> stoi(), stoll(), stof(), stod() seem less useful, though providing
>> a portable C++03 implementation wouldn't be bad.
>
> Don't those functions require std::string as input? I'd be nice to
> have generic variants.

I wouldn't use any of these. The functions I wrote for this purpose
take either a const char*, or a const char** if you want the iterator
advanced.

For int-to-string, you pass begin and end pointers, and the digits
are written from right to left, padding with zeroes or truncating the
numeral as necessary. A function taking just the int and returning a
string is a trivial wrapper around this one.

Josh


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