Boost logo

Boost :

From: brianjparker (brianjparker_at_[hidden])
Date: 2002-02-03 22:06:38


--- In boost_at_y..., "Joe Gottman" <joegottman_at_w...> wrote:
>
> ----- Original Message -----
> From: "brianjparker" <brianjparker_at_h...>
> To: <boost_at_y...>
> Sent: Sunday, January 27, 2002 10:10 PM
> Subject: [boost] Re: to_string(v)
>
>
> >
> > A minor improvement may be to add an overload-
> >
> > inline
> > std::string to_string(const char* in)
> > {
> > std::string str(in);
> > return str;
> > }
> >
> >
>
> How would this interact with 0? If we had to_string(const char
*) and
> then someone called to_string(0), would to_string(const char *) be
called?
> If so, this could be a problem, because I think that the string
constructor
> that takes a const char * will crash if it is passed a null char
pointer.
> Even if it didn't crash, it would return an empty string, not the
string
> "0".

I don't think this is a problem- the literal 0 is of type int and so
the generated template overload is an exact match and so would be
called in preference to casting 0 to const char*. Certainly it works
OK with Intel C++ 6.

,Brian Parker


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