|
Boost : |
From: brianjparker (brianjparker_at_[hidden])
Date: 2002-01-27 22:10:33
--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> I just wrote this:
>
> template<class V> std::string to_string(V const & v)
> {
> std::ostringstream os;
> os << v;
> return os.str();
> }
>
> template<> std::string to_string(std::string const & v)
> {
> return v;
> }
>
> for Nth time. Why don't we have this in Boost? And where should it
go?
I agree wholeheartedly with this- I use this function regularly and
would like to see it in the Boost utility header.
(An example that I use a lot is in debug messages, e.g. one can
use "Var 1:" + to_string(var) + "etc...").
A minor improvement may be to add an overload-
inline
std::string to_string(const char* in)
{
std::string str(in);
return str;
}
which, although redundant, is more efficient for a C string argument
(of course, one could just use std::string(in) directly, but using
to_string is more consistent).
In fact, this would be an excellent function to add to the standard
<string> header in the next library revision- perhaps someone on the
committee could put in a formal proposal to add it.
,Brian Parker
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk